From b4109be58431bcd915d032d97c24a9119947da9c Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Fri, 28 Sep 2018 09:01:38 -0700 Subject: [PATCH 01/57] Confirm that generic API method name is not needed after call creation --- test/cpp/end2end/generic_end2end_test.cc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc index 88a1227ca2e..0bdaf83618a 100644 --- a/test/cpp/end2end/generic_end2end_test.cc +++ b/test/cpp/end2end/generic_end2end_test.cc @@ -123,8 +123,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 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 send_buffer = From 1c766d5c6d2ddec146f3140eeefff7557ecd8228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Sojma?= Date: Tue, 6 Nov 2018 15:03:15 +0100 Subject: [PATCH 02/57] ability to set "no_proxy" with use of "no_grpc_proxy" environment variable --- src/core/ext/filters/client_channel/http_proxy.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 8951a2920c4..3f05b23ffaf 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -122,7 +122,10 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, server_uri); goto no_use_proxy; } - no_proxy_str = gpr_getenv("no_proxy"); + no_proxy_str = gpr_getenv("no_grpc_proxy"); + if (no_proxy_str == nullptr) { + no_proxy_str = gpr_getenv("no_proxy"); + } if (no_proxy_str != nullptr) { static const char* NO_PROXY_SEPARATOR = ","; bool use_proxy = true; From c2ddef218fb066fd217432ac3703720d4671cdf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Sojma?= Date: Tue, 6 Nov 2018 15:16:56 +0100 Subject: [PATCH 03/57] ability to set proxy with use of "grpc_proxy" environment variable --- src/core/ext/filters/client_channel/http_proxy.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 3f05b23ffaf..94ef2c55ec8 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -47,10 +47,12 @@ static char* get_http_proxy_server(char** user_cred) { char* proxy_name = nullptr; char** authority_strs = nullptr; size_t authority_nstrs; - /* Prefer using 'https_proxy'. Fallback on 'http_proxy' if it is not set. The + /* Prefer using 'grpc_proxy'. Fallback on 'http_proxy' if it is not set. + * Also prefer using 'https_proxy' with fallback on 'http_proxy'. The * fallback behavior can be removed if there's a demand for it. */ - char* uri_str = gpr_getenv("https_proxy"); + char* uri_str = gpr_getenv("grpc_proxy"); + if (uri_str == nullptr) uri_str = gpr_getenv("https_proxy"); if (uri_str == nullptr) uri_str = gpr_getenv("http_proxy"); if (uri_str == nullptr) return nullptr; grpc_uri* uri = grpc_uri_parse(uri_str, false /* suppress_errors */); @@ -122,6 +124,7 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, server_uri); goto no_use_proxy; } + /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */ no_proxy_str = gpr_getenv("no_grpc_proxy"); if (no_proxy_str == nullptr) { no_proxy_str = gpr_getenv("no_proxy"); From 43279fc50ba83296fb43234aeab67910e68e7fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zden=C4=9Bk=20Sojma?= Date: Tue, 6 Nov 2018 15:24:40 +0100 Subject: [PATCH 04/57] coding style update --- src/core/ext/filters/client_channel/http_proxy.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/ext/filters/client_channel/http_proxy.cc b/src/core/ext/filters/client_channel/http_proxy.cc index 94ef2c55ec8..26c8b439e75 100644 --- a/src/core/ext/filters/client_channel/http_proxy.cc +++ b/src/core/ext/filters/client_channel/http_proxy.cc @@ -126,9 +126,7 @@ static bool proxy_mapper_map_name(grpc_proxy_mapper* mapper, } /* Prefer using 'no_grpc_proxy'. Fallback on 'no_proxy' if it is not set. */ no_proxy_str = gpr_getenv("no_grpc_proxy"); - if (no_proxy_str == nullptr) { - no_proxy_str = gpr_getenv("no_proxy"); - } + if (no_proxy_str == nullptr) no_proxy_str = gpr_getenv("no_proxy"); if (no_proxy_str != nullptr) { static const char* NO_PROXY_SEPARATOR = ","; bool use_proxy = true; From 3fe631d1b6ffa7ab9f46d120ef27298e4ede3d9c Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Tue, 5 Mar 2019 13:57:41 -0800 Subject: [PATCH 05/57] Update doc about using clang-5.0 --- BUILDING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILDING.md b/BUILDING.md index 615b371db6e..2d757f58dca 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -12,7 +12,7 @@ gRPC C++ - Building from source If you plan to build from source and run tests, install the following as well: ```sh $ [sudo] apt-get install libgflags-dev libgtest-dev - $ [sudo] apt-get install clang libc++-dev + $ [sudo] apt-get install clang-5.0 libc++-dev ``` ## MacOS From 477ebef532b0163d87ba8c068c84d2adb67a3477 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 28 May 2019 14:18:15 -0700 Subject: [PATCH 06/57] Remove CreateChannel() method from LB helper API. --- .../filters/client_channel/client_channel.cc | 5 -- .../client_channel/client_channel_factory.h | 4 -- .../ext/filters/client_channel/lb_policy.h | 6 --- .../client_channel/lb_policy/grpclb/grpclb.cc | 18 ++----- .../lb_policy/grpclb/grpclb_channel.cc | 15 +++++- .../lb_policy/grpclb/grpclb_channel.h | 11 ++++- .../lb_policy/grpclb/grpclb_channel_secure.cc | 48 ++++++++++++------- .../client_channel/lb_policy/xds/xds.cc | 31 ++---------- .../lb_policy/xds/xds_channel.cc | 14 +++++- .../lb_policy/xds/xds_channel.h | 10 +++- .../lb_policy/xds/xds_channel_secure.cc | 41 +++++++++++----- .../client_channel/resolving_lb_policy.cc | 7 --- .../chttp2/client/insecure/channel_create.cc | 43 +++++++++-------- .../client/secure/secure_channel_create.cc | 45 +++++++++-------- test/core/util/test_lb_policies.cc | 5 -- test/cpp/microbenchmarks/bm_call_create.cc | 4 -- 16 files changed, 156 insertions(+), 151 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index c0586d459b2..acbf1238113 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -960,11 +960,6 @@ class ChannelData::ClientChannelControlHelper return subchannel; } - 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 picker) override { diff --git a/src/core/ext/filters/client_channel/client_channel_factory.h b/src/core/ext/filters/client_channel/client_channel_factory.h index 21f78a833df..42bc7cb505f 100644 --- a/src/core/ext/filters/client_channel/client_channel_factory.h +++ b/src/core/ext/filters/client_channel/client_channel_factory.h @@ -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); diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index 2ac7df63b7d..237b5930d4a 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -191,12 +191,6 @@ class LoadBalancingPolicy : public InternallyRefCounted { virtual Subchannel* 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, diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index ed6e8de3f21..26c9fdfc9c1 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -294,8 +294,6 @@ class GrpcLb : public LoadBalancingPolicy { : parent_(std::move(parent)) {} Subchannel* 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 picker) override; void RequestReresolution() override; @@ -625,15 +623,6 @@ Subchannel* GrpcLb::Helper::CreateSubchannel(const grpc_channel_args& args) { 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 picker) { if (parent_->shutting_down_) return; @@ -1232,7 +1221,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 @@ -1259,7 +1248,7 @@ grpc_channel_args* BuildBalancerChannelArgs( args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Make any necessary modifications for security. - return grpc_lb_policy_grpclb_modify_lb_channel_args(addresses, new_args); + return ModifyGrpclbBalancerChannelArgs(addresses, new_args); } // @@ -1464,8 +1453,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); grpc_core::channelz::ChannelNode* channel_node = grpc_channel_get_channelz_node(lb_channel_); diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc index b713e26713f..c7237632c0a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc @@ -18,9 +18,20 @@ #include +#include + #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 diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h index c78ba36cf1d..1458233022f 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h @@ -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 \ */ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 892cdeb27b7..376209fa7e2 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -22,6 +22,7 @@ #include +#include #include #include @@ -35,6 +36,7 @@ #include "src/core/lib/slice/slice_internal.h" namespace grpc_core { + namespace { int BalancerNameCmp(const grpc_core::UniquePtr& a, @@ -65,37 +67,49 @@ RefCountedPtr 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 args_to_remove; + InlinedVector args_to_add; // Add arg for targets info table. - grpc_core::RefCountedPtr - target_authority_table = grpc_core::CreateTargetAuthorityTable(addresses); - args_to_add[num_args_to_add++] = - grpc_core::CreateTargetAuthorityTableChannelArg( - target_authority_table.get()); + RefCountedPtr 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 creds_sans_call_creds; + RefCountedPtr 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); + 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 diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index 819bad6c00d..08ecec5c8ba 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -338,8 +338,6 @@ class XdsLb : public LoadBalancingPolicy { : parent_(std::move(parent)) {} Subchannel* 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 picker) override; void RequestReresolution() override; @@ -378,8 +376,6 @@ class XdsLb : public LoadBalancingPolicy { : entry_(std::move(entry)) {} Subchannel* 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 picker) override; void RequestReresolution() override; @@ -592,15 +588,6 @@ Subchannel* 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 picker) { if (parent_->shutting_down_) return; @@ -722,7 +709,7 @@ ServerAddressList ProcessServerlist(const xds_grpclb_serverlist* serverlist) { XdsLb::BalancerChannelState::BalancerChannelState( const char* balancer_name, const grpc_channel_args& args, - grpc_core::RefCountedPtr parent_xdslb_policy) + RefCountedPtr parent_xdslb_policy) : InternallyRefCounted(&grpc_lb_xds_trace), xdslb_policy_(std::move(parent_xdslb_policy)), lb_call_backoff_( @@ -735,8 +722,7 @@ XdsLb::BalancerChannelState::BalancerChannelState( GRPC_CLOSURE_INIT(&on_connectivity_changed_, &XdsLb::BalancerChannelState::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); StartCallLocked(); } @@ -1325,7 +1311,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 @@ -1348,7 +1334,7 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) { args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add, GPR_ARRAY_SIZE(args_to_add)); // Make any necessary modifications for security. - return grpc_lb_policy_xds_modify_lb_channel_args(new_args); + return ModifyXdsBalancerChannelArgs(new_args); } // @@ -2010,15 +1996,6 @@ Subchannel* 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 picker) { if (entry_->parent_->shutting_down_) return; diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc index 0aa145a24e5..386517d6427 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc @@ -18,9 +18,19 @@ #include +#include + #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 diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h index f713b7f563d..516bac1df25 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h @@ -23,14 +23,20 @@ #include +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 \ */ diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc index 7f8c232d6d0..ad5e7cbbc2e 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc @@ -20,9 +20,11 @@ #include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h" +#include + +#include #include #include -#include #include "src/core/ext/filters/client_channel/client_channel.h" #include "src/core/ext/filters/client_channel/server_address.h" @@ -33,29 +35,44 @@ #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 args_to_remove; + InlinedVector 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 creds_sans_call_creds; + RefCountedPtr 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); + 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 diff --git a/src/core/ext/filters/client_channel/resolving_lb_policy.cc b/src/core/ext/filters/client_channel/resolving_lb_policy.cc index 4e383f65dd1..6f3cfe813e8 100644 --- a/src/core/ext/filters/client_channel/resolving_lb_policy.cc +++ b/src/core/ext/filters/client_channel/resolving_lb_policy.cc @@ -112,13 +112,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 picker) override { if (parent_->resolver_ == nullptr) return; // Shutting down. diff --git a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc index 0d61abd2a01..cbd522d6e50 100644 --- a/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +++ b/src/core/ext/transport/chttp2/client/insecure/channel_create.cc @@ -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 canonical_target = - ResolverRegistry::AddDefaultPrefixIfNeeded(target); - grpc_arg arg = grpc_channel_arg_string_create( - const_cast(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 canonical_target = + ResolverRegistry::AddDefaultPrefixIfNeeded(target); + grpc_arg arg = grpc_channel_arg_string_create( + const_cast(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 diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index bc38ff25c79..b18d742ed12 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -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 canonical_target = - ResolverRegistry::AddDefaultPrefixIfNeeded(target); - grpc_arg arg = grpc_channel_arg_string_create( - const_cast(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 canonical_target = + ResolverRegistry::AddDefaultPrefixIfNeeded(target); + grpc_arg arg = grpc_channel_arg_string_create( + const_cast(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); } diff --git a/test/core/util/test_lb_policies.cc b/test/core/util/test_lb_policies.cc index b871f04bc9e..684e7495d36 100644 --- a/test/core/util/test_lb_policies.cc +++ b/test/core/util/test_lb_policies.cc @@ -145,11 +145,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 picker) override { parent_->channel_control_helper()->UpdateState( diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc index 3bd1464b2aa..e687c644516 100644 --- a/test/cpp/microbenchmarks/bm_call_create.cc +++ b/test/cpp/microbenchmarks/bm_call_create.cc @@ -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) { From 5ce3f688800cf6dfe8ba7be14dd824b8c399aa6d Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 29 May 2019 12:52:05 -0700 Subject: [PATCH 07/57] fix handling of insecure channels in grpclb and xds --- .../client_channel/lb_policy/grpclb/grpclb_channel_secure.cc | 4 ++++ .../client_channel/lb_policy/xds/xds_channel_secure.cc | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index 376209fa7e2..5bc4f5157ad 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -103,6 +103,10 @@ 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); diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc index ad5e7cbbc2e..720d5a01d9d 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc @@ -66,6 +66,10 @@ 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); From c914fbbc1d9be8030e76d07a005927a63109fc61 Mon Sep 17 00:00:00 2001 From: Lev Pachmanov Date: Fri, 26 Jul 2019 19:49:57 +0300 Subject: [PATCH 08/57] catch the error if socket initialization fails --- src/core/lib/iomgr/tcp_server_custom.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/iomgr/tcp_server_custom.cc b/src/core/lib/iomgr/tcp_server_custom.cc index 767404be21d..61b307fc4c0 100644 --- a/src/core/lib/iomgr/tcp_server_custom.cc +++ b/src/core/lib/iomgr/tcp_server_custom.cc @@ -391,7 +391,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); From 96742f41ff19d2aa36adfa37bdff26f89041ccb4 Mon Sep 17 00:00:00 2001 From: Ryo Murakami Date: Tue, 30 Jul 2019 08:04:02 +0900 Subject: [PATCH 09/57] update Scripting Runtime Version empty commit empty commit --- src/csharp/experimental/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/csharp/experimental/README.md b/src/csharp/experimental/README.md index b5c106e320c..cfa9c4b0324 100644 --- a/src/csharp/experimental/README.md +++ b/src/csharp/experimental/README.md @@ -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/) From 6bca0f04a3cf8530c457fae2fb8da5330421f08b Mon Sep 17 00:00:00 2001 From: easy Date: Thu, 15 Aug 2019 11:34:55 +1000 Subject: [PATCH 10/57] Use opencensus::tags::TagKey. opencensus::stats::TagKey is deprecated. --- .../registered_opencensus_objects.h | 31 ++++++++++--------- src/cpp/ext/filters/census/grpc_plugin.cc | 17 +++++----- src/cpp/ext/filters/census/grpc_plugin.h | 9 +++--- src/cpp/server/load_reporter/load_reporter.cc | 11 ++++--- src/cpp/server/load_reporter/load_reporter.h | 11 ++++--- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/core/ext/filters/load_reporting/registered_opencensus_objects.h b/src/core/ext/filters/load_reporting/registered_opencensus_objects.h index 4eacda7c02a..ed11ff42239 100644 --- a/src/core/ext/filters/load_reporting/registered_opencensus_objects.h +++ b/src/core/ext/filters/load_reporting/registered_opencensus_objects.h @@ -22,6 +22,7 @@ #include #include "opencensus/stats/stats.h" +#include "opencensus/tags/tag_key.h" #include "src/cpp/server/load_reporter/constants.h" @@ -80,33 +81,33 @@ inline ::opencensus::stats::MeasureDouble MeasureOtherCallMetric() { // Tags. -inline ::opencensus::stats::TagKey TagKeyToken() { - static const ::opencensus::stats::TagKey token = - opencensus::stats::TagKey::Register(kTagKeyToken); +inline ::opencensus::tags::TagKey TagKeyToken() { + static const ::opencensus::tags::TagKey token = + opencensus::tags::TagKey::Register(kTagKeyToken); return token; } -inline ::opencensus::stats::TagKey TagKeyHost() { - static const ::opencensus::stats::TagKey token = - opencensus::stats::TagKey::Register(kTagKeyHost); +inline ::opencensus::tags::TagKey TagKeyHost() { + static const ::opencensus::tags::TagKey token = + opencensus::tags::TagKey::Register(kTagKeyHost); return token; } -inline ::opencensus::stats::TagKey TagKeyUserId() { - static const ::opencensus::stats::TagKey token = - opencensus::stats::TagKey::Register(kTagKeyUserId); +inline ::opencensus::tags::TagKey TagKeyUserId() { + static const ::opencensus::tags::TagKey token = + opencensus::tags::TagKey::Register(kTagKeyUserId); return token; } -inline ::opencensus::stats::TagKey TagKeyStatus() { - static const ::opencensus::stats::TagKey token = - opencensus::stats::TagKey::Register(kTagKeyStatus); +inline ::opencensus::tags::TagKey TagKeyStatus() { + static const ::opencensus::tags::TagKey token = + opencensus::tags::TagKey::Register(kTagKeyStatus); return token; } -inline ::opencensus::stats::TagKey TagKeyMetricName() { - static const ::opencensus::stats::TagKey token = - opencensus::stats::TagKey::Register(kTagKeyMetricName); +inline ::opencensus::tags::TagKey TagKeyMetricName() { + static const ::opencensus::tags::TagKey token = + opencensus::tags::TagKey::Register(kTagKeyMetricName); return token; } diff --git a/src/cpp/ext/filters/census/grpc_plugin.cc b/src/cpp/ext/filters/census/grpc_plugin.cc index c5018f0673a..63d6f1bde48 100644 --- a/src/cpp/ext/filters/census/grpc_plugin.cc +++ b/src/cpp/ext/filters/census/grpc_plugin.cc @@ -22,6 +22,7 @@ #include +#include "opencensus/tags/tag_key.h" #include "opencensus/trace/span.h" #include "src/cpp/ext/filters/census/channel_filter.h" #include "src/cpp/ext/filters/census/client_filter.h" @@ -33,27 +34,27 @@ namespace grpc { // These measure definitions should be kept in sync across opencensus // implementations--see // https://github.com/census-instrumentation/opencensus-java/blob/master/contrib/grpc_metrics/src/main/java/io/opencensus/contrib/grpc/metrics/RpcMeasureConstants.java. -::opencensus::stats::TagKey ClientMethodTagKey() { +::opencensus::tags::TagKey ClientMethodTagKey() { static const auto method_tag_key = - ::opencensus::stats::TagKey::Register("grpc_client_method"); + ::opencensus::tags::TagKey::Register("grpc_client_method"); return method_tag_key; } -::opencensus::stats::TagKey ClientStatusTagKey() { +::opencensus::tags::TagKey ClientStatusTagKey() { static const auto status_tag_key = - ::opencensus::stats::TagKey::Register("grpc_client_status"); + ::opencensus::tags::TagKey::Register("grpc_client_status"); return status_tag_key; } -::opencensus::stats::TagKey ServerMethodTagKey() { +::opencensus::tags::TagKey ServerMethodTagKey() { static const auto method_tag_key = - ::opencensus::stats::TagKey::Register("grpc_server_method"); + ::opencensus::tags::TagKey::Register("grpc_server_method"); return method_tag_key; } -::opencensus::stats::TagKey ServerStatusTagKey() { +::opencensus::tags::TagKey ServerStatusTagKey() { static const auto status_tag_key = - ::opencensus::stats::TagKey::Register("grpc_server_status"); + ::opencensus::tags::TagKey::Register("grpc_server_status"); return status_tag_key; } diff --git a/src/cpp/ext/filters/census/grpc_plugin.h b/src/cpp/ext/filters/census/grpc_plugin.h index 13176759e37..14f2481681d 100644 --- a/src/cpp/ext/filters/census/grpc_plugin.h +++ b/src/cpp/ext/filters/census/grpc_plugin.h @@ -24,6 +24,7 @@ #include "absl/strings/string_view.h" #include "include/grpcpp/opencensus.h" #include "opencensus/stats/stats.h" +#include "opencensus/tags/tag_key.h" namespace grpc_impl { class ServerContext; @@ -32,10 +33,10 @@ class ServerContext; namespace grpc { // The tag keys set when recording RPC stats. -::opencensus::stats::TagKey ClientMethodTagKey(); -::opencensus::stats::TagKey ClientStatusTagKey(); -::opencensus::stats::TagKey ServerMethodTagKey(); -::opencensus::stats::TagKey ServerStatusTagKey(); +::opencensus::tags::TagKey ClientMethodTagKey(); +::opencensus::tags::TagKey ClientStatusTagKey(); +::opencensus::tags::TagKey ServerMethodTagKey(); +::opencensus::tags::TagKey ServerStatusTagKey(); // Names of measures used by the plugin--users can create views on these // measures but should not record data for them. diff --git a/src/cpp/server/load_reporter/load_reporter.cc b/src/cpp/server/load_reporter/load_reporter.cc index 422ea62efd5..b4c5e57c354 100644 --- a/src/cpp/server/load_reporter/load_reporter.cc +++ b/src/cpp/server/load_reporter/load_reporter.cc @@ -29,6 +29,7 @@ #include "src/cpp/server/load_reporter/load_reporter.h" #include "opencensus/stats/internal/set_aggregation_window.h" +#include "opencensus/tags/tag_key.h" namespace grpc { namespace load_reporter { @@ -38,12 +39,12 @@ CpuStatsProvider::CpuStatsSample CpuStatsProviderDefaultImpl::GetCpuStats() { } CensusViewProvider::CensusViewProvider() - : tag_key_token_(::opencensus::stats::TagKey::Register(kTagKeyToken)), - tag_key_host_(::opencensus::stats::TagKey::Register(kTagKeyHost)), - tag_key_user_id_(::opencensus::stats::TagKey::Register(kTagKeyUserId)), - tag_key_status_(::opencensus::stats::TagKey::Register(kTagKeyStatus)), + : tag_key_token_(::opencensus::tags::TagKey::Register(kTagKeyToken)), + tag_key_host_(::opencensus::tags::TagKey::Register(kTagKeyHost)), + tag_key_user_id_(::opencensus::tags::TagKey::Register(kTagKeyUserId)), + tag_key_status_(::opencensus::tags::TagKey::Register(kTagKeyStatus)), tag_key_metric_name_( - ::opencensus::stats::TagKey::Register(kTagKeyMetricName)) { + ::opencensus::tags::TagKey::Register(kTagKeyMetricName)) { // One view related to starting a call. auto vd_start_count = ::opencensus::stats::ViewDescriptor() diff --git a/src/cpp/server/load_reporter/load_reporter.h b/src/cpp/server/load_reporter/load_reporter.h index 766e02a407a..44767ee841e 100644 --- a/src/cpp/server/load_reporter/load_reporter.h +++ b/src/cpp/server/load_reporter/load_reporter.h @@ -34,6 +34,7 @@ #include "src/proto/grpc/lb/v1/load_reporter.grpc.pb.h" #include "opencensus/stats/stats.h" +#include "opencensus/tags/tag_key.h" namespace grpc { namespace load_reporter { @@ -75,11 +76,11 @@ class CensusViewProvider { private: ViewDescriptorMap view_descriptor_map_; // Tag keys. - ::opencensus::stats::TagKey tag_key_token_; - ::opencensus::stats::TagKey tag_key_host_; - ::opencensus::stats::TagKey tag_key_user_id_; - ::opencensus::stats::TagKey tag_key_status_; - ::opencensus::stats::TagKey tag_key_metric_name_; + ::opencensus::tags::TagKey tag_key_token_; + ::opencensus::tags::TagKey tag_key_host_; + ::opencensus::tags::TagKey tag_key_user_id_; + ::opencensus::tags::TagKey tag_key_status_; + ::opencensus::tags::TagKey tag_key_metric_name_; }; // The default implementation fetches the real stats from Census. From a08f043b59fe2820f25d296629cac3948a1b67c4 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 20 Aug 2019 08:05:27 -0700 Subject: [PATCH 11/57] add missing build deps --- BUILD | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/BUILD b/BUILD index c510757c35d..1ce579812d1 100644 --- a/BUILD +++ b/BUILD @@ -1215,6 +1215,7 @@ grpc_cc_library( "grpc_client_channel", "grpc_lb_upb", "grpc_resolver_fake", + "grpc_transport_chttp2_client_insecure", ], ) @@ -1241,6 +1242,7 @@ grpc_cc_library( "grpc_lb_upb", "grpc_resolver_fake", "grpc_secure", + "grpc_transport_chttp2_client_secure", ], ) @@ -1264,6 +1266,7 @@ grpc_cc_library( "grpc_base", "grpc_client_channel", "grpc_resolver_fake", + "grpc_transport_chttp2_client_insecure", ], ) @@ -1288,6 +1291,7 @@ grpc_cc_library( "grpc_client_channel", "grpc_resolver_fake", "grpc_secure", + "grpc_transport_chttp2_client_secure", ], ) From 8ce740cfe0dea62ab7eeffdfa218b012af6fc9aa Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 21 Aug 2019 14:24:06 -0700 Subject: [PATCH 12/57] Switch py_proto_library from using src to deps to conform with google3 --- bazel/python_rules.bzl | 8 ++++---- bazel/test/python_test_repo/BUILD | 6 +++--- src/proto/grpc/testing/BUILD | 6 +++--- src/proto/grpc/testing/proto2/BUILD.bazel | 4 ++-- src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel | 2 +- .../grpcio_health_checking/grpc_health/v1/BUILD.bazel | 2 +- .../grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 0f00d53b6fb..12f51f8b172 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -61,22 +61,22 @@ _generate_pb2_src = rule( def py_proto_library( name, - srcs, + deps, **kwargs): """Generate python code for a protobuf. Args: name: The name of the target. - srcs: A list of proto_library dependencies. Must contain a single element. + deps: A list of proto_library dependencies. Must contain a single element. """ codegen_target = "_{}_codegen".format(name) - if len(srcs) != 1: + if len(deps) != 1: fail("Can only compile a single proto at a time.") _generate_pb2_src( name = codegen_target, - deps = srcs, + deps = deps, **kwargs ) diff --git a/bazel/test/python_test_repo/BUILD b/bazel/test/python_test_repo/BUILD index 0df3700ec93..8aba6a78528 100644 --- a/bazel/test/python_test_repo/BUILD +++ b/bazel/test/python_test_repo/BUILD @@ -29,7 +29,7 @@ proto_library( py_proto_library( name = "helloworld_py_pb2", - srcs = [":helloworld_proto"], + deps = [":helloworld_proto"], ) py_grpc_library( @@ -40,12 +40,12 @@ py_grpc_library( py_proto_library( name = "duration_py_pb2", - srcs = ["@com_google_protobuf//:duration_proto"], + deps = ["@com_google_protobuf//:duration_proto"], ) py_proto_library( name = "timestamp_py_pb2", - srcs = ["@com_google_protobuf//:timestamp_proto"], + deps = ["@com_google_protobuf//:timestamp_proto"], ) py_test( diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 8bea8ed7ca0..bc481606500 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -75,7 +75,7 @@ proto_library( py_proto_library( name = "empty_py_pb2", - srcs = [":empty_proto_descriptor"], + deps = [":empty_proto_descriptor"], ) py_grpc_library( @@ -97,7 +97,7 @@ proto_library( py_proto_library( name = "py_messages_proto", - srcs = [":messages_proto_descriptor"], + deps = [":messages_proto_descriptor"], ) py_grpc_library( @@ -206,7 +206,7 @@ proto_library( py_proto_library( name = "py_test_proto", - srcs = [":test_proto_descriptor"], + deps = [":test_proto_descriptor"], ) py_grpc_library( diff --git a/src/proto/grpc/testing/proto2/BUILD.bazel b/src/proto/grpc/testing/proto2/BUILD.bazel index 668d0a484ea..8acb233302a 100644 --- a/src/proto/grpc/testing/proto2/BUILD.bazel +++ b/src/proto/grpc/testing/proto2/BUILD.bazel @@ -10,7 +10,7 @@ proto_library( py_proto_library( name = "empty2_proto", - srcs = [":empty2_proto_descriptor"], + deps = [":empty2_proto_descriptor"], ) proto_library( @@ -23,6 +23,6 @@ proto_library( py_proto_library( name = "empty2_extensions_proto", - srcs = [":empty2_extensions_proto_descriptor"], + deps = [":empty2_extensions_proto_descriptor"], ) diff --git a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel index c0a7e3d3026..5f4e512e9f4 100644 --- a/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel +++ b/src/python/grpcio_channelz/grpc_channelz/v1/BUILD.bazel @@ -3,7 +3,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "channelz_py_pb2", - srcs = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], + deps = ["//src/proto/grpc/channelz:channelz_proto_descriptors"], ) py_grpc_library( diff --git a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel index 0ee176f0506..62a44df7707 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel +++ b/src/python/grpcio_health_checking/grpc_health/v1/BUILD.bazel @@ -3,7 +3,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "health_py_pb2", - srcs = ["//src/proto/grpc/health/v1:health_proto_descriptor",], + deps = ["//src/proto/grpc/health/v1:health_proto_descriptor",], ) py_grpc_library( diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel index 49bc517caf1..10077fd9568 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/BUILD.bazel @@ -5,7 +5,7 @@ package(default_visibility = ["//visibility:public"]) py_proto_library( name = "reflection_py_pb2", - srcs = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor",], + deps = ["//src/proto/grpc/reflection/v1alpha:reflection_proto_descriptor",], ) py_grpc_library( From ba04bafede63e1760385f14f40d8d322699e31ed Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 21 Aug 2019 14:39:54 -0700 Subject: [PATCH 13/57] And the examples directory --- examples/python/cancellation/BUILD.bazel | 2 +- examples/python/multiprocessing/BUILD | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/python/cancellation/BUILD.bazel b/examples/python/cancellation/BUILD.bazel index 41b394a07a2..17b1b20168e 100644 --- a/examples/python/cancellation/BUILD.bazel +++ b/examples/python/cancellation/BUILD.bazel @@ -26,7 +26,7 @@ proto_library( py_proto_library( name = "hash_name_py_pb2", - srcs = [":hash_name_proto"], + deps = [":hash_name_proto"], ) py_grpc_library( diff --git a/examples/python/multiprocessing/BUILD b/examples/python/multiprocessing/BUILD index 257523f14bb..490aea0c1e6 100644 --- a/examples/python/multiprocessing/BUILD +++ b/examples/python/multiprocessing/BUILD @@ -23,7 +23,7 @@ proto_library( py_proto_library( name = "prime_proto_pb2", - srcs = [":prime_proto"], + deps = [":prime_proto"], ) py_grpc_library( From 013ac94821951e456ff99f0326caba1bb88bf1e1 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 21 Aug 2019 15:10:02 -0700 Subject: [PATCH 14/57] And another --- examples/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/BUILD b/examples/BUILD index 6f801963c6e..1455d25dc76 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -67,7 +67,7 @@ proto_library( py_proto_library( name = "helloworld_py_pb2", - srcs = [":protos/helloworld_proto"], + deps = [":protos/helloworld_proto"], ) py_grpc_library( From f8286f3c90ecc76980095bf1198d25686e4f77ed Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Fri, 23 Aug 2019 14:01:31 -0700 Subject: [PATCH 15/57] Update triage rotation --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/cleanup_request.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/pull_request_template.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f3ed8399dc2..e44c8966012 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -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 --- diff --git a/.github/ISSUE_TEMPLATE/cleanup_request.md b/.github/ISSUE_TEMPLATE/cleanup_request.md index 65e56772541..4fe128984b9 100644 --- a/.github/ISSUE_TEMPLATE/cleanup_request.md +++ b/.github/ISSUE_TEMPLATE/cleanup_request.md @@ -2,7 +2,7 @@ name: Request a cleanup about: Suggest a cleanup in our repository labels: kind/internal cleanup -assignees: AspirinSJL +assignees: mhaidrygoog --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 2be15ac785c..499de024dd4 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -2,7 +2,7 @@ name: Request a feature about: Suggest an idea for this project labels: kind/enhancement -assignees: AspirinSJL +assignees: mhaidrygoog --- diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fba14a5db00..ac8c41a9f26 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,4 +8,4 @@ If you know who should review your pull request, please remove the mentioning be --> -@AspirinSJL \ No newline at end of file +@mhaidrygoog \ No newline at end of file From 5294f49d11d27773904728614a78ee27ee0f10d7 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Fri, 23 Aug 2019 15:33:52 -0700 Subject: [PATCH 16/57] Init needs to be called in case of bad creds --- src/cpp/client/create_channel.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index ca7038b8893..c6041edcb36 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -38,7 +38,7 @@ std::shared_ptr CreateCustomChannelImpl( const std::shared_ptr& creds, const grpc::ChannelArguments& args) { grpc::GrpcLibraryCodegen - init_lib; // We need to call init in case of a bad creds. + init_lib; // We need to call init in case of bad creds. return creds ? creds->CreateChannelImpl(target, args) : grpc::CreateChannelInternal( "", @@ -69,6 +69,8 @@ std::shared_ptr CreateCustomChannelWithInterceptors( std::vector< std::unique_ptr> interceptor_creators) { + grpc::GrpcLibraryCodegen + init_lib; // We need to call init in case of bad creds. return creds ? creds->CreateChannelWithInterceptors( target, args, std::move(interceptor_creators)) : grpc::CreateChannelInternal( From 3728329033f51895ce2603bb65b49be19e3c3129 Mon Sep 17 00:00:00 2001 From: yang-g Date: Fri, 23 Aug 2019 16:15:17 -0700 Subject: [PATCH 17/57] return unavailable on transport closed --- .../ext/transport/chttp2/transport/chttp2_transport.cc | 7 +++++++ test/core/end2end/tests/max_connection_age.cc | 2 +- test/core/end2end/tests/shutdown_finishes_calls.cc | 4 +--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 73235756dfb..5f5c480f9dc 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -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); diff --git a/test/core/end2end/tests/max_connection_age.cc b/test/core/end2end/tests/max_connection_age.cc index fcb0aaffc4a..50c790d8521 100644 --- a/test/core/end2end/tests/max_connection_age.cc +++ b/test/core/end2end/tests/max_connection_age.cc @@ -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); diff --git a/test/core/end2end/tests/shutdown_finishes_calls.cc b/test/core/end2end/tests/shutdown_finishes_calls.cc index 5dd5bb2ad6c..60b738ef9ef 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.cc +++ b/test/core/end2end/tests/shutdown_finishes_calls.cc @@ -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); From 6e159d3ee38c089c6be7391d18af4c836a38139e Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Fri, 23 Aug 2019 15:04:13 -0700 Subject: [PATCH 18/57] Fix hpack parser fuzzer failure. Fix crash when nullptr is passed to ManagedMemorySlice::Equals(). --- src/core/lib/slice/slice_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/slice/slice_utils.h b/src/core/lib/slice/slice_utils.h index 161300abe1e..e80de6d2ece 100644 --- a/src/core/lib/slice/slice_utils.h +++ b/src/core/lib/slice/slice_utils.h @@ -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; } }; From 6f2f9ae2c362eac6b76da442606b2486623b4d6b Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 23 Aug 2019 10:07:17 -0700 Subject: [PATCH 19/57] import ProtoRPC and GRPCCallOptions in ProtoService --- src/objective-c/ProtoRPC/ProtoService.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/objective-c/ProtoRPC/ProtoService.h b/src/objective-c/ProtoRPC/ProtoService.h index 8543f5dee43..45376a94353 100644 --- a/src/objective-c/ProtoRPC/ProtoService.h +++ b/src/objective-c/ProtoRPC/ProtoService.h @@ -18,15 +18,12 @@ #import -@class GRPCProtoCall; +#import "ProtoRPC.h" +#import + @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" From 25b56ee1dd75597b16ee4f323e4fad4f14f3e1a6 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 23 Aug 2019 16:25:13 -0700 Subject: [PATCH 20/57] Add LDXX to Rakefile --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 8123dc541dc..f791d7e1c85 100755 --- a/Rakefile +++ b/Rakefile @@ -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 From e21ec5d4d5d7f549d65f32535229ed0eb58bd73c Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 23 Aug 2019 16:46:01 -0700 Subject: [PATCH 21/57] clang-format --- src/objective-c/ProtoRPC/ProtoService.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/ProtoRPC/ProtoService.h b/src/objective-c/ProtoRPC/ProtoService.h index 45376a94353..fd8a86bb2b2 100644 --- a/src/objective-c/ProtoRPC/ProtoService.h +++ b/src/objective-c/ProtoRPC/ProtoService.h @@ -18,8 +18,8 @@ #import -#import "ProtoRPC.h" #import +#import "ProtoRPC.h" @protocol GRXWriteable; @class GRXWriter; From 4dffd825242d28df4995073d1864ee036f44cbca Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Sat, 24 Aug 2019 11:57:57 -0700 Subject: [PATCH 22/57] Fix type unmatch --- src/cpp/client/secure_credentials.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index ebff8af3e5a..d870dca158a 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -407,7 +407,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. From 3869f43953b9995a46e5ad3210446a78e18eabbb Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 26 Aug 2019 08:56:17 +0200 Subject: [PATCH 23/57] only run libuv portability tests as build-only --- tools/run_tests/run_tests_matrix.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/run_tests/run_tests_matrix.py b/tools/run_tests/run_tests_matrix.py index 06a52b0f76e..80c0a7d6455 100755 --- a/tools/run_tests/run_tests_matrix.py +++ b/tools/run_tests/run_tests_matrix.py @@ -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) From b804ce974a75a2d32fe186f6abdc3493eb851ee4 Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Mon, 26 Aug 2019 08:43:46 -0700 Subject: [PATCH 24/57] Implemented _abort method on ServicerContext This acquires a lock from the _condition member of the context's _rpc and then aborts the _rpc directly --- .../grpcio_testing/grpc_testing/_server/_servicer_context.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py index 63a1b1aec95..0f9c4ed4b00 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py @@ -74,7 +74,8 @@ class ServicerContext(grpc.ServicerContext): _common.fuss_with_metadata(trailing_metadata)) def abort(self, code, details): - raise NotImplementedError() + self._rpc._condition.acquire() + self._rpc._abort(code, details) def abort_with_status(self, status): raise NotImplementedError() From 57586a1ca7f17b1916aed3dea4ff8de872dbf853 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Fri, 3 May 2019 08:11:00 -0700 Subject: [PATCH 25/57] Rename gettid() functions. glibc 2.30 will declare its own gettid; see https://sourceware.org/git/?p=glibc.git;a=commit;h=1d0fc213824eaa2a8f8c4385daaa698ee8fb7c92. Rename the grpc versions to avoid naming conflicts. --- src/core/lib/gpr/log_linux.cc | 6 ++---- src/core/lib/gpr/log_posix.cc | 4 ++-- src/core/lib/iomgr/ev_epollex_linux.cc | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/lib/gpr/log_linux.cc b/src/core/lib/gpr/log_linux.cc index 81026e5689b..8b597b4cf2f 100644 --- a/src/core/lib/gpr/log_linux.cc +++ b/src/core/lib/gpr/log_linux.cc @@ -40,9 +40,7 @@ #include #include -// 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(now.tv_sec); final_slash = strrchr(args->file, '/'); diff --git a/src/core/lib/gpr/log_posix.cc b/src/core/lib/gpr/log_posix.cc index b6edc14ab6b..2f7c6ce3760 100644 --- a/src/core/lib/gpr/log_posix.cc +++ b/src/core/lib/gpr/log_posix.cc @@ -31,7 +31,7 @@ #include #include -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); diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index c2d80c08ddb..4a83cb6c215 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -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, From 1ab9225dcef223610cd4992482363bd927f41a5c Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Mon, 26 Aug 2019 10:57:35 -0700 Subject: [PATCH 26/57] Release the lock on the RPC object condition --- .../grpcio_testing/grpc_testing/_server/_servicer_context.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py index 0f9c4ed4b00..b1277fa4a42 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py @@ -76,6 +76,7 @@ class ServicerContext(grpc.ServicerContext): def abort(self, code, details): self._rpc._condition.acquire() self._rpc._abort(code, details) + self._rpc._condition.release() def abort_with_status(self, status): raise NotImplementedError() From 5c173084f8af589a1bad3ba44cabedb1c781470b Mon Sep 17 00:00:00 2001 From: Neeraj Kashyap Date: Mon, 26 Aug 2019 11:07:58 -0700 Subject: [PATCH 27/57] condition acquire and release with context manager Was previously unfamiliar with the contex manager wrapper around threading primitives. --- .../grpcio_testing/grpc_testing/_server/_servicer_context.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py index b1277fa4a42..6fa8c6b3ba8 100644 --- a/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py +++ b/src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py @@ -74,9 +74,8 @@ class ServicerContext(grpc.ServicerContext): _common.fuss_with_metadata(trailing_metadata)) def abort(self, code, details): - self._rpc._condition.acquire() - self._rpc._abort(code, details) - self._rpc._condition.release() + with self._rpc._condition: + self._rpc._abort(code, details) def abort_with_status(self, status): raise NotImplementedError() From d9c0d498f224366263b0fc7cff9752eec48172cd Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 26 Aug 2019 11:33:44 -0700 Subject: [PATCH 28/57] Stop the failing tests --- src/python/grpcio_tests/commands.py | 5 ++++- .../grpcio_tests/tests/unit/_local_credentials_test.py | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 61d8bdc1f7b..d30daacd5ac 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -160,7 +160,10 @@ class TestGevent(setuptools.Command): ) BANNED_WINDOWS_TESTS = ( # TODO(https://github.com/grpc/grpc/pull/15411) enable this test - 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback',) + 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback', + # TODO(https://github.com/grpc/grpc/issues/20078) enable this test + 'unit._local_credentials_test.LocalCredentialsTest', + ) description = 'run tests with gevent. Assumes grpc/gevent are installed' user_options = [] diff --git a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py index 80a21af1cef..14b68cb5907 100644 --- a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py @@ -49,6 +49,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( From 5b1899160a3af87a2f90b9732b9222b156fe3cb5 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Mon, 26 Aug 2019 11:51:28 -0700 Subject: [PATCH 29/57] Run auditwheel-show to python artifacts --- .../grpc_artifact_python_manylinux_x64/Dockerfile | 6 +++--- .../grpc_artifact_python_manylinux_x86/Dockerfile | 7 ++++--- tools/run_tests/artifacts/build_artifact_python.sh | 2 ++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile b/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile index 6c2b1cc4740..c36ad6bec58 100644 --- a/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile +++ b/tools/dockerfile/grpc_artifact_python_manylinux_x64/Dockerfile @@ -32,7 +32,7 @@ RUN /opt/python/cp37-cp37m/bin/pip install cython #################################################### # Install auditwheel with fix for namespace packages RUN git clone https://github.com/pypa/auditwheel /usr/local/src/auditwheel -RUN cd /usr/local/src/auditwheel && git checkout bf071b38c9fe78b025ea05c78b1cb61d7cb09939 -RUN /opt/python/cp35-cp35m/bin/pip install /usr/local/src/auditwheel +RUN cd /usr/local/src/auditwheel && git checkout 2.1 +RUN /opt/python/cp36-cp36m/bin/pip install /usr/local/src/auditwheel RUN rm /usr/local/bin/auditwheel -RUN cd /usr/local/bin && ln -s /opt/python/cp35-cp35m/bin/auditwheel +RUN cd /usr/local/bin && ln -s /opt/python/cp36-cp36m/bin/auditwheel diff --git a/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile b/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile index 8f409dd2162..a33e0517ae2 100644 --- a/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile +++ b/tools/dockerfile/grpc_artifact_python_manylinux_x86/Dockerfile @@ -32,7 +32,8 @@ RUN /opt/python/cp37-cp37m/bin/pip install cython #################################################### # Install auditwheel with fix for namespace packages RUN git clone https://github.com/pypa/auditwheel /usr/local/src/auditwheel -RUN cd /usr/local/src/auditwheel && git checkout bf071b38c9fe78b025ea05c78b1cb61d7cb09939 -RUN /opt/python/cp35-cp35m/bin/pip install /usr/local/src/auditwheel +RUN cd /usr/local/src/auditwheel && git checkout 2.1 +RUN /opt/python/cp36-cp36m/bin/pip install /usr/local/src/auditwheel RUN rm /usr/local/bin/auditwheel -RUN cd /usr/local/bin && ln -s /opt/python/cp35-cp35m/bin/auditwheel +RUN cd /usr/local/bin && ln -s /opt/python/cp36-cp36m/bin/auditwheel + diff --git a/tools/run_tests/artifacts/build_artifact_python.sh b/tools/run_tests/artifacts/build_artifact_python.sh index 55fd4ead04d..7393b88a768 100755 --- a/tools/run_tests/artifacts/build_artifact_python.sh +++ b/tools/run_tests/artifacts/build_artifact_python.sh @@ -79,10 +79,12 @@ ${SETARCH_CMD} "${PYTHON}" tools/distrib/python/grpcio_tools/setup.py bdist_whee if [ "$GRPC_BUILD_MANYLINUX_WHEEL" != "" ] then for wheel in dist/*.whl; do + "${AUDITWHEEL}" show "$wheel" | tee /dev/stderr | grep \"manylinux1 "${AUDITWHEEL}" repair "$wheel" -w "$ARTIFACT_DIR" rm "$wheel" done for wheel in tools/distrib/python/grpcio_tools/dist/*.whl; do + "${AUDITWHEEL}" show "$wheel" | tee /dev/stderr | grep \"manylinux1 "${AUDITWHEEL}" repair "$wheel" -w "$ARTIFACT_DIR" rm "$wheel" done From 750a8ab6ca22e85df38d3d54845ac489c94ac0df Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 26 Aug 2019 12:05:21 -0700 Subject: [PATCH 30/57] Fix import --- src/python/grpcio_tests/tests/unit/_local_credentials_test.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py index 14b68cb5907..8690505b861 100644 --- a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py @@ -14,6 +14,7 @@ """Test of RPCs made using local credentials.""" import unittest +import os from concurrent.futures import ThreadPoolExecutor import grpc From 80163ef83b800d9aad1740b1762514a7aca5dddc Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Sat, 24 Aug 2019 10:39:38 -0700 Subject: [PATCH 31/57] Update BUILD file accordingly --- src/objective-c/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/src/objective-c/BUILD b/src/objective-c/BUILD index e71dd3eed81..5f53486d17e 100644 --- a/src/objective-c/BUILD +++ b/src/objective-c/BUILD @@ -232,6 +232,7 @@ grpc_objc_library( ], hdrs = [ "ProtoRPC/ProtoMethod.h", + "ProtoRPC/ProtoRPC.h", "ProtoRPC/ProtoRPCLegacy.h", "ProtoRPC/ProtoService.h", ], From 8f403431a153b75665f8d737489862e9e1460aff Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 26 Aug 2019 13:57:20 -0700 Subject: [PATCH 32/57] Try to disable it again --- src/python/grpcio_tests/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index d30daacd5ac..2ea6de28bb7 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -162,7 +162,7 @@ class TestGevent(setuptools.Command): # TODO(https://github.com/grpc/grpc/pull/15411) enable this test 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback', # TODO(https://github.com/grpc/grpc/issues/20078) enable this test - 'unit._local_credentials_test.LocalCredentialsTest', + 'unit._local_credentials_test.LocalCredentialsTest.test_local_tcp', ) description = 'run tests with gevent. Assumes grpc/gevent are installed' user_options = [] From 2707fd0bd406488665776dfd89987d95e26e2d51 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Fri, 23 Aug 2019 15:47:40 -0700 Subject: [PATCH 33/57] Added GRPC_USE_CPP_STD_LIB flag --- BUILD | 5 +++++ bazel/grpc_build_system.bzl | 3 +++ include/grpc/impl/codegen/port_platform.h | 9 +++++++++ .../lb_policy/xds/xds_client_stats.cc | 8 ++++++++ .../lb_policy/xds/xds_load_balancer_api.cc | 8 ++++++++ src/core/lib/gprpp/abstract.h | 10 ++++++++++ src/core/lib/gprpp/map.h | 16 ++++++++++++++++ src/core/lib/security/credentials/credentials.h | 10 ++++++++-- test/core/gprpp/map_test.cc | 9 +++++++++ .../linux/grpc_bazel_build_in_docker.sh | 1 + 10 files changed, 77 insertions(+), 2 deletions(-) diff --git a/BUILD b/BUILD index c510757c35d..6855ad9602e 100644 --- a/BUILD +++ b/BUILD @@ -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" diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index f816fe14ff4..23f90d0dc80 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -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), diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index dd49a66fe25..bab57657a00 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -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 diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc index 85f7d669ec0..a866d50b3a6 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc @@ -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; } diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc index ac87053d47f..16d5f9a1391 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc @@ -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, +#else Pair, +#endif XdsClientStats::LocalityStats::Snapshot>& input, upb_arena* arena) { // Set sub_zone. diff --git a/src/core/lib/gprpp/abstract.h b/src/core/lib/gprpp/abstract.h index 5b7018e07e0..ea68e3ab041 100644 --- a/src/core/lib/gprpp/abstract.h +++ b/src/core/lib/gprpp/abstract.h @@ -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 */ diff --git a/src/core/lib/gprpp/map.h b/src/core/lib/gprpp/map.h index 705b605e5b9..134625775cf 100644 --- a/src/core/lib/gprpp/map.h +++ b/src/core/lib/gprpp/map.h @@ -27,12 +27,17 @@ #include #include +#if GRPC_USE_CPP_STD_LIB +#include +#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 > +using Map = std::map; + +#else // GRPC_USE_CPP_STD_LIB + namespace testing { class MapTest; } @@ -537,5 +549,9 @@ int Map::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 */ diff --git a/src/core/lib/security/credentials/credentials.h b/src/core/lib/security/credentials/credentials.h index f3fbe881598..b43405b0861 100644 --- a/src/core/lib/security/credentials/credentials.h +++ b/src/core/lib/security/credentials/credentials.h @@ -110,11 +110,17 @@ struct grpc_channel_credentials create_security_connector( grpc_core::RefCountedPtr 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 diff --git a/test/core/gprpp/map_test.cc b/test/core/gprpp/map_test.cc index b0be7960b57..7dc1ba636f3 100644 --- a/test/core/gprpp/map_test.cc +++ b/test/core/gprpp/map_test.cc @@ -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 diff --git a/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh b/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh index 24598f43f02..8487ec49bbd 100755 --- a/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh +++ b/tools/internal_ci/linux/grpc_bazel_build_in_docker.sh @@ -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 From 630e6ab2212a99c26f4cda89f1459a0205f70763 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 26 Aug 2019 15:55:42 -0700 Subject: [PATCH 34/57] Use the correct machanism to ignore test in Windows --- src/python/grpcio_tests/commands.py | 4 +--- src/python/grpcio_tests/tests/unit/_local_credentials_test.py | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 2ea6de28bb7..3758d995a97 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -161,8 +161,6 @@ class TestGevent(setuptools.Command): BANNED_WINDOWS_TESTS = ( # TODO(https://github.com/grpc/grpc/pull/15411) enable this test 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback', - # TODO(https://github.com/grpc/grpc/issues/20078) enable this test - 'unit._local_credentials_test.LocalCredentialsTest.test_local_tcp', ) description = 'run tests with gevent. Assumes grpc/gevent are installed' user_options = [] @@ -189,7 +187,7 @@ class TestGevent(setuptools.Command): loader = tests.Loader() loader.loadTestsFromNames(['tests']) runner = tests.Runner() - if sys.platform == 'win32': + if os.name == 'nt': runner.skip_tests(self.BANNED_TESTS + self.BANNED_WINDOWS_TESTS) else: runner.skip_tests(self.BANNED_TESTS) diff --git a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py index 8690505b861..7f3e8cc41c9 100644 --- a/src/python/grpcio_tests/tests/unit/_local_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_local_credentials_test.py @@ -33,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( From a2990a053cdeb1737062b11188a1357a18441f62 Mon Sep 17 00:00:00 2001 From: Lidi Zheng Date: Mon, 26 Aug 2019 15:57:02 -0700 Subject: [PATCH 35/57] Revert changes in src/python/grpcio_tests/commands.py --- src/python/grpcio_tests/commands.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 3758d995a97..61d8bdc1f7b 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -160,8 +160,7 @@ class TestGevent(setuptools.Command): ) BANNED_WINDOWS_TESTS = ( # TODO(https://github.com/grpc/grpc/pull/15411) enable this test - 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback', - ) + 'unit._dns_resolver_test.DNSResolverTest.test_connect_loopback',) description = 'run tests with gevent. Assumes grpc/gevent are installed' user_options = [] @@ -187,7 +186,7 @@ class TestGevent(setuptools.Command): loader = tests.Loader() loader.loadTestsFromNames(['tests']) runner = tests.Runner() - if os.name == 'nt': + if sys.platform == 'win32': runner.skip_tests(self.BANNED_TESTS + self.BANNED_WINDOWS_TESTS) else: runner.skip_tests(self.BANNED_TESTS) From 15b279ab69dc4447ed960673987e4b031441117c Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Mon, 26 Aug 2019 15:09:20 -0700 Subject: [PATCH 36/57] Add auditwheel to linux docker --- .../grpc_artifact_linux_x64/Dockerfile | 12 ++++++++++-- .../grpc_artifact_linux_x86/Dockerfile | 16 ++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/tools/dockerfile/grpc_artifact_linux_x64/Dockerfile b/tools/dockerfile/grpc_artifact_linux_x64/Dockerfile index a0fef12d6e1..b3c16951229 100644 --- a/tools/dockerfile/grpc_artifact_linux_x64/Dockerfile +++ b/tools/dockerfile/grpc_artifact_linux_x64/Dockerfile @@ -57,10 +57,10 @@ RUN \curl -sSL https://get.rvm.io | bash -s stable # Install Ruby 2.1 RUN /bin/bash -l -c "rvm install ruby-2.1" RUN /bin/bash -l -c "rvm use --default ruby-2.1" -RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" +RUN /bin/bash -l -c "echo 'gem: --no-document' > ~/.gemrc" RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc" -RUN /bin/bash -l -c "gem install bundler -v 1.17.3 --no-ri --no-rdoc" +RUN /bin/bash -l -c "gem install bundler -v 1.17.3 --no-document" ################## @@ -79,6 +79,14 @@ RUN echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf RUN sed -i '/deb http:\/\/deb.debian.org\/debian jessie-updates main/d' /etc/apt/sources.list RUN apt-get update && apt-get install -t jessie-backports -y cmake && apt-get clean + +################## +# Python AuditWheel dependencies (needed to check manylinux1 compatibility) + +RUN apt-get install -y python3 python3-pip +RUN pip3 install auditwheel==1.10.0 + + RUN mkdir /var/local/jenkins # Define the default command. diff --git a/tools/dockerfile/grpc_artifact_linux_x86/Dockerfile b/tools/dockerfile/grpc_artifact_linux_x86/Dockerfile index 8709fe0426c..c9054653067 100644 --- a/tools/dockerfile/grpc_artifact_linux_x86/Dockerfile +++ b/tools/dockerfile/grpc_artifact_linux_x86/Dockerfile @@ -14,7 +14,7 @@ # Docker file for building gRPC artifacts. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN sed -i '/deb http:\/\/http.debian.net\/debian jessie-updates main/d' /etc/apt/sources.list # Install Git and basic packages. @@ -49,7 +49,6 @@ RUN apt-get update && apt-get install -y \ ################## # Ruby dependencies -# Install rvm # Install rvm RUN apt-get update && apt-get install -y gnupg2 RUN gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB @@ -58,10 +57,11 @@ RUN \curl -sSL https://get.rvm.io | bash -s stable # Install Ruby 2.1 RUN /bin/bash -l -c "rvm install ruby-2.1" RUN /bin/bash -l -c "rvm use --default ruby-2.1" -RUN /bin/bash -l -c "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc" +RUN /bin/bash -l -c "echo 'gem: --no-document' > ~/.gemrc" RUN /bin/bash -l -c "echo 'export PATH=/usr/local/rvm/bin:$PATH' >> ~/.bashrc" RUN /bin/bash -l -c "echo 'rvm --default use ruby-2.1' >> ~/.bashrc" -RUN /bin/bash -l -c "gem install bundler -v 1.17.3 --no-ri --no-rdoc" +RUN /bin/bash -l -c "gem install bundler -v 1.17.3 --no-document" + ################## # C# dependencies (needed to build grpc_csharp_ext) @@ -72,6 +72,14 @@ RUN echo 'Acquire::Check-Valid-Until "false";' > /etc/apt/apt.conf RUN sed -i '/deb http:\/\/deb.debian.org\/debian jessie-updates main/d' /etc/apt/sources.list RUN apt-get update && apt-get install -t jessie-backports -y cmake && apt-get clean + +################## +# Python AuditWheel dependencies (needed to check manylinux1 compatibility) + +RUN apt-get install -y python3 python3-pip +RUN pip3 install auditwheel==1.10.0 + + RUN mkdir /var/local/jenkins # Define the default command. From cc4b946e3c37c7c7bb672ba92b43ef8708a65013 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 27 Aug 2019 08:35:09 -0700 Subject: [PATCH 37/57] Replace 32bit/debian:jessie with i386/debian:jessie --- .../tools/dockerfile/test/cxx_jessie_x86/Dockerfile.template | 2 +- tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile | 2 +- tools/dockerfile/distribtest/node_jessie_x86/Dockerfile | 2 +- tools/dockerfile/distribtest/python_dev_jessie_x86/Dockerfile | 2 +- tools/dockerfile/distribtest/python_jessie_x86/Dockerfile | 2 +- tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile | 2 +- tools/dockerfile/test/cxx_jessie_x86/Dockerfile | 2 +- .../helper_scripts/prepare_build_linux_perf_multilang_rc | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/tools/dockerfile/test/cxx_jessie_x86/Dockerfile.template b/templates/tools/dockerfile/test/cxx_jessie_x86/Dockerfile.template index 36f243c3405..8d9012d6acf 100644 --- a/templates/tools/dockerfile/test/cxx_jessie_x86/Dockerfile.template +++ b/templates/tools/dockerfile/test/cxx_jessie_x86/Dockerfile.template @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - FROM 32bit/debian:jessie + FROM i386/debian:jessie RUN sed -i '/deb http:\/\/http.debian.net\/debian jessie-updates main/d' /etc/apt/sources.list <%include file="../../apt_get_basic.include"/> diff --git a/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile index aec936a5b8c..96b318d8ae0 100644 --- a/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/csharp_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN apt-get update && apt-get install -y apt-transport-https && apt-get clean diff --git a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile index 1db31a5d9c6..aa9695e3173 100644 --- a/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/node_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN apt-get update && apt-get install -y curl diff --git a/tools/dockerfile/distribtest/python_dev_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/python_dev_jessie_x86/Dockerfile index 5e0b8efe756..b1d1a31061a 100644 --- a/tools/dockerfile/distribtest/python_dev_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/python_dev_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN apt-get update && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile index 140c6cb7afa..d5b63421c59 100644 --- a/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/python_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN apt-get update && apt-get install -y python python-pip diff --git a/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile b/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile index b011f837dd5..04cfa51069c 100644 --- a/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile +++ b/tools/dockerfile/distribtest/ruby_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN apt-get update && apt-get install -y ruby-full diff --git a/tools/dockerfile/test/cxx_jessie_x86/Dockerfile b/tools/dockerfile/test/cxx_jessie_x86/Dockerfile index 59b86d7247c..18611e60d23 100644 --- a/tools/dockerfile/test/cxx_jessie_x86/Dockerfile +++ b/tools/dockerfile/test/cxx_jessie_x86/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM 32bit/debian:jessie +FROM i386/debian:jessie RUN sed -i '/deb http:\/\/http.debian.net\/debian jessie-updates main/d' /etc/apt/sources.list # Install Git and basic packages. diff --git a/tools/internal_ci/helper_scripts/prepare_build_linux_perf_multilang_rc b/tools/internal_ci/helper_scripts/prepare_build_linux_perf_multilang_rc index f1031aedf39..bb1287fee51 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_linux_perf_multilang_rc +++ b/tools/internal_ci/helper_scripts/prepare_build_linux_perf_multilang_rc @@ -30,7 +30,7 @@ sudo pip install tabulate export PATH="$HOME/.rbenv/bin:$PATH" eval "$(rbenv init -)" gem list bundler -gem install bundler --no-ri --no-rdoc +gem install bundler --no-document # Allow SSH to Kokoro performance workers without explicit key verification gsutil cp gs://grpc-testing-secrets/grpc_kokoro_performance_ssh_keys/id_rsa ~/.ssh From 18be57b4dfb3b2b6341f2d0903b5fce12282c1fa Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 27 Aug 2019 11:21:06 -0700 Subject: [PATCH 38/57] LB policy API changes suggested by Sanjay. --- .../filters/client_channel/client_channel.cc | 10 ++-- .../ext/filters/client_channel/lb_policy.cc | 2 +- .../ext/filters/client_channel/lb_policy.h | 55 ++++++++++--------- .../client_channel/lb_policy/grpclb/grpclb.cc | 5 +- .../client_channel/lb_policy/xds/xds.cc | 9 ++- .../client_channel/resolving_lb_policy.cc | 4 +- test/core/util/test_lb_policies.cc | 2 +- 7 files changed, 43 insertions(+), 44 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 63bd737e931..f88c1228de0 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -1345,11 +1345,11 @@ class ChannelData::ClientChannelControlHelper // No-op -- we should never get this from ResolvingLoadBalancingPolicy. void RequestReresolution() override {} - void AddTraceEvent(TraceSeverity severity, const char* message) override { + void AddTraceEvent(TraceSeverity severity, StringView message) override { if (chand_->channelz_node_ != nullptr) { chand_->channelz_node_->AddTraceEvent( ConvertSeverityEnum(severity), - grpc_slice_from_copied_string(message)); + grpc_slice_from_copied_buffer(message.data(), message.size())); } } @@ -3730,8 +3730,8 @@ const char* PickResultTypeName( return "COMPLETE"; case LoadBalancingPolicy::PickResult::PICK_QUEUE: return "QUEUE"; - case LoadBalancingPolicy::PickResult::PICK_TRANSIENT_FAILURE: - return "TRANSIENT_FAILURE"; + case LoadBalancingPolicy::PickResult::PICK_FAILED: + return "FAILED"; } GPR_UNREACHABLE_CODE(return "UNKNOWN"); } @@ -3792,7 +3792,7 @@ void CallData::StartPickLocked(void* arg, grpc_error* error) { result.subchannel.get(), grpc_error_string(result.error)); } switch (result.type) { - case LoadBalancingPolicy::PickResult::PICK_TRANSIENT_FAILURE: { + case LoadBalancingPolicy::PickResult::PICK_FAILED: { // If we're shutting down, fail all RPCs. grpc_error* disconnect_error = chand->disconnect_error(); if (disconnect_error != GRPC_ERROR_NONE) { diff --git a/src/core/ext/filters/client_channel/lb_policy.cc b/src/core/ext/filters/client_channel/lb_policy.cc index 3207f888044..41a7d2d07be 100644 --- a/src/core/ext/filters/client_channel/lb_policy.cc +++ b/src/core/ext/filters/client_channel/lb_policy.cc @@ -129,7 +129,7 @@ void LoadBalancingPolicy::QueuePicker::CallExitIdle(void* arg, LoadBalancingPolicy::PickResult LoadBalancingPolicy::TransientFailurePicker::Pick(PickArgs args) { PickResult result; - result.type = PickResult::PICK_TRANSIENT_FAILURE; + result.type = PickResult::PICK_FAILED; result.error = GRPC_ERROR_REF(error_); return result; } diff --git a/src/core/ext/filters/client_channel/lb_policy.h b/src/core/ext/filters/client_channel/lb_policy.h index ea4962cdb77..6e7447dd172 100644 --- a/src/core/ext/filters/client_channel/lb_policy.h +++ b/src/core/ext/filters/client_channel/lb_policy.h @@ -42,15 +42,15 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount; /// /// Channel: An abstraction that manages connections to backend servers /// on behalf of a client application. The application creates a channel -/// for a given server name and then sends RPCs on it, and the channel -/// figures out which backend server to send each RPC to. A channel +/// for a given server name and then sends calls (RPCs) on it, and the +/// channel figures out which backend server to send each call to. A channel /// contains a resolver, a load balancing policy (or a tree of LB policies), /// and a set of one or more subchannels. /// /// Subchannel: A subchannel represents a connection to one backend server. /// The LB policy decides which subchannels to create, manages the /// connectivity state of those subchannels, and decides which subchannel -/// to send any given RPC to. +/// to send any given call to. /// /// Resolver: A plugin that takes a gRPC server URI and resolves it to a /// list of one or more addresses and a service config, as described @@ -59,12 +59,12 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount; /// /// Load Balancing (LB) Policy: A plugin that takes a list of addresses /// from the resolver, maintains and manages a subchannel for each -/// backend address, and decides which subchannel to send each RPC on. +/// backend address, and decides which subchannel to send each call on. /// An LB policy has two parts: /// - A LoadBalancingPolicy, which deals with the control plane work of /// managing subchannels. /// - A SubchannelPicker, which handles the data plane work of -/// determining which subchannel a given RPC should be sent on. +/// determining which subchannel a given call should be sent on. /// LoadBalacingPolicy API. /// @@ -78,6 +78,7 @@ extern DebugOnlyTraceFlag grpc_trace_lb_policy_refcount; class LoadBalancingPolicy : public InternallyRefCounted { public: /// Interface for accessing per-call state. + /// Implemented by the client channel and used by the SubchannelPicker. class CallState { public: CallState() = default; @@ -93,6 +94,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { }; /// Interface for accessing metadata. + /// Implemented by the client channel and used by the SubchannelPicker. class MetadataInterface { public: // Implementations whose iterators fit in intptr_t may internally @@ -123,7 +125,7 @@ class LoadBalancingPolicy : public InternallyRefCounted { GRPC_ABSTRACT_BASE_CLASS }; - /// Arguments used when picking a subchannel for an RPC. + /// Arguments used when picking a subchannel for a call. struct PickArgs { /// Initial metadata associated with the picking call. /// The LB policy may use the existing metadata to influence its routing @@ -135,24 +137,23 @@ class LoadBalancingPolicy : public InternallyRefCounted { CallState* call_state; }; - /// The result of picking a subchannel for an RPC. + /// The result of picking a subchannel for a call. struct PickResult { enum ResultType { - /// Pick complete. If connected_subchannel is non-null, client channel - /// can immediately proceed with the call on connected_subchannel; - /// otherwise, call should be dropped. + /// Pick complete. If \a subchannel is non-null, the client channel + /// will immediately proceed with the call on that subchannel; + /// otherwise, it will drop the call. PICK_COMPLETE, /// Pick cannot be completed until something changes on the control - /// plane. Client channel will queue the pick and try again the + /// plane. The client channel will queue the pick and try again the /// next time the picker is updated. PICK_QUEUE, - /// LB policy is in transient failure. If the pick is wait_for_ready, - /// client channel will wait for the next picker and try again; - /// otherwise, the call will be failed immediately (although it may - /// be retried if the client channel is configured to do so). - /// The Pick() method will set its error parameter if this value is - /// returned. - PICK_TRANSIENT_FAILURE, + /// Pick failed. If the call is wait_for_ready, the client channel + /// will wait for the next picker and try again; otherwise, it + /// will immediately fail the call with the status indicated via + /// \a error (although the call may be retried if the client channel + /// is configured to do so). + PICK_FAILED, }; ResultType type; @@ -160,14 +161,14 @@ class LoadBalancingPolicy : public InternallyRefCounted { /// subchannel, or nullptr if the LB policy decides to drop the call. RefCountedPtr subchannel; - /// Used only if type is PICK_TRANSIENT_FAILURE. - /// Error to be set when returning a transient failure. + /// Used only if type is PICK_FAILED. + /// Error to be set when returning a failure. // TODO(roth): Replace this with something similar to grpc::Status, // so that we don't expose grpc_error to this API. grpc_error* error = GRPC_ERROR_NONE; /// Used only if type is PICK_COMPLETE. - /// Callback set by lb policy to be notified of trailing metadata. + /// Callback set by LB policy to be notified of trailing metadata. /// The user_data argument will be set to the /// recv_trailing_metadata_ready_user_data field. /// recv_trailing_metadata will be set to the metadata, which may be @@ -184,11 +185,12 @@ class LoadBalancingPolicy : public InternallyRefCounted { }; /// A subchannel picker is the object used to pick the subchannel to - /// use for a given RPC. + /// use for a given call. This is implemented by the LB policy and + /// used by the client channel to perform picks. /// /// Pickers are intended to encapsulate all of the state and logic /// needed on the data plane (i.e., to actually process picks for - /// individual RPCs sent on the channel) while excluding all of the + /// individual calls sent on the channel) while excluding all of the /// state and logic needed on the control plane (i.e., resolver /// updates, connectivity state notifications, etc); the latter should /// live in the LB policy object itself. @@ -206,8 +208,8 @@ class LoadBalancingPolicy : public InternallyRefCounted { GRPC_ABSTRACT_BASE_CLASS }; - /// A proxy object used by the LB policy to communicate with the client - /// channel. + /// A proxy object implemented by the client channel and used by the + /// LB policy to communicate with the channel. // TODO(juanlishen): Consider adding a mid-layer subclass that helps handle // things like swapping in pending policy when it's ready. Currently, we are // duplicating the logic in many subclasses. @@ -235,10 +237,9 @@ class LoadBalancingPolicy : public InternallyRefCounted { virtual void RequestReresolution() GRPC_ABSTRACT; /// Adds a trace message associated with the channel. - /// Does NOT take ownership of \a message. enum TraceSeverity { TRACE_INFO, TRACE_WARNING, TRACE_ERROR }; virtual void AddTraceEvent(TraceSeverity severity, - const char* message) GRPC_ABSTRACT; + StringView message) GRPC_ABSTRACT; GRPC_ABSTRACT_BASE_CLASS }; diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index 6a565e057b9..c63717bdb92 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -298,7 +298,7 @@ class GrpcLb : public LoadBalancingPolicy { void UpdateState(grpc_connectivity_state state, UniquePtr picker) override; void RequestReresolution() override; - void AddTraceEvent(TraceSeverity severity, const char* message) override; + void AddTraceEvent(TraceSeverity severity, StringView message) override; void set_child(LoadBalancingPolicy* child) { child_ = child; } @@ -756,8 +756,7 @@ void GrpcLb::Helper::RequestReresolution() { } } -void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity, - const char* message) { +void GrpcLb::Helper::AddTraceEvent(TraceSeverity severity, StringView message) { if (parent_->shutting_down_ || (!CalledByPendingChild() && !CalledByCurrentChild())) { return; diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index 75fa544c80a..f40e58e47c5 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -436,7 +436,7 @@ class XdsLb : public LoadBalancingPolicy { void UpdateState(grpc_connectivity_state state, UniquePtr picker) override; void RequestReresolution() override; - void AddTraceEvent(TraceSeverity severity, const char* message) override; + void AddTraceEvent(TraceSeverity severity, StringView message) override; void set_child(LoadBalancingPolicy* child) { child_ = child; } @@ -487,8 +487,7 @@ class XdsLb : public LoadBalancingPolicy { void UpdateState(grpc_connectivity_state state, UniquePtr picker) override; void RequestReresolution() override; - void AddTraceEvent(TraceSeverity severity, - const char* message) override; + void AddTraceEvent(TraceSeverity severity, StringView message) override; void set_child(LoadBalancingPolicy* child) { child_ = child; } private: @@ -774,7 +773,7 @@ void XdsLb::FallbackHelper::RequestReresolution() { } void XdsLb::FallbackHelper::AddTraceEvent(TraceSeverity severity, - const char* message) { + StringView message) { if (parent_->shutting_down_ || (!CalledByPendingFallback() && !CalledByCurrentFallback())) { return; @@ -2510,7 +2509,7 @@ void XdsLb::LocalityMap::LocalityEntry::Helper::RequestReresolution() { } void XdsLb::LocalityMap::LocalityEntry::Helper::AddTraceEvent( - TraceSeverity severity, const char* message) { + TraceSeverity severity, StringView message) { if (entry_->parent_->shutting_down_ || (!CalledByPendingChild() && !CalledByCurrentChild())) { return; diff --git a/src/core/ext/filters/client_channel/resolving_lb_policy.cc b/src/core/ext/filters/client_channel/resolving_lb_policy.cc index b3b455b0ce8..c85e948a55b 100644 --- a/src/core/ext/filters/client_channel/resolving_lb_policy.cc +++ b/src/core/ext/filters/client_channel/resolving_lb_policy.cc @@ -160,7 +160,7 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper } } - void AddTraceEvent(TraceSeverity severity, const char* message) override {} + void AddTraceEvent(TraceSeverity severity, StringView message) override {} void set_child(LoadBalancingPolicy* child) { child_ = child; } @@ -435,7 +435,7 @@ void ResolvingLoadBalancingPolicy::ConcatenateAndAddChannelTraceLocked( size_t len = 0; UniquePtr message(gpr_strvec_flatten(&v, &len)); channel_control_helper()->AddTraceEvent(ChannelControlHelper::TRACE_INFO, - message.get()); + StringView(message.get())); gpr_strvec_destroy(&v); } } diff --git a/test/core/util/test_lb_policies.cc b/test/core/util/test_lb_policies.cc index 77e186c6d49..0539a498965 100644 --- a/test/core/util/test_lb_policies.cc +++ b/test/core/util/test_lb_policies.cc @@ -166,7 +166,7 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy parent_->channel_control_helper()->RequestReresolution(); } - void AddTraceEvent(TraceSeverity severity, const char* message) override { + void AddTraceEvent(TraceSeverity severity, StringView message) override { parent_->channel_control_helper()->AddTraceEvent(severity, message); } From 905f52852e6bfeaa09969bc89c9495da01cd31f7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 27 Aug 2019 12:03:10 -0400 Subject: [PATCH 39/57] make python dockerfiles buildable again --- .../dockerfile/debian_testing_repo.include | 3 -- .../grpc_interop_python/Dockerfile.template | 2 +- .../tools/dockerfile/python_stretch.include | 4 ++- .../Dockerfile.template | 16 ++++++++-- .../Dockerfile.template | 2 +- .../Dockerfile.template | 13 +++++---- .../test/sanity/Dockerfile.template | 2 +- .../grpc_interop_python/Dockerfile | 9 +++--- .../test/python_stretch_2.7_x64/Dockerfile | 7 ++--- .../test/python_stretch_3.5_x64/Dockerfile | 7 ++--- .../test/python_stretch_3.6_x64/Dockerfile | 22 ++++++++++---- .../test/python_stretch_3.7_x64/Dockerfile | 9 +++--- .../test/python_stretch_3.8_x64/Dockerfile | 20 +++++++------ .../python_stretch_3.8_x64/get_cpython.sh | 29 ------------------- tools/dockerfile/test/sanity/Dockerfile | 9 +++--- 15 files changed, 73 insertions(+), 81 deletions(-) delete mode 100644 templates/tools/dockerfile/debian_testing_repo.include delete mode 100644 tools/dockerfile/test/python_stretch_3.8_x64/get_cpython.sh diff --git a/templates/tools/dockerfile/debian_testing_repo.include b/templates/tools/dockerfile/debian_testing_repo.include deleted file mode 100644 index 1a5248e2264..00000000000 --- a/templates/tools/dockerfile/debian_testing_repo.include +++ /dev/null @@ -1,3 +0,0 @@ -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local diff --git a/templates/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile.template b/templates/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile.template index f584a2378eb..ac939620d07 100644 --- a/templates/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile.template +++ b/templates/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile.template @@ -16,5 +16,5 @@ <%include file="../../python_stretch.include"/> - RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev + RUN apt-get update && apt-get -t stable install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 diff --git a/templates/tools/dockerfile/python_stretch.include b/templates/tools/dockerfile/python_stretch.include index 45bafe51842..43ba98ae64c 100644 --- a/templates/tools/dockerfile/python_stretch.include +++ b/templates/tools/dockerfile/python_stretch.include @@ -3,7 +3,9 @@ FROM debian:stretch <%include file="./apt_get_basic.include"/> <%include file="./gcp_api_libraries.include"/> <%include file="./apt_get_python_27.include"/> -<%include file="./debian_testing_repo.include"/> +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local <%include file="./run_tests_addons.include"/> # Define the default command. CMD ["bash"] diff --git a/templates/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile.template b/templates/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile.template index a5dcf196f2b..2c2cb6de08b 100644 --- a/templates/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile.template @@ -16,5 +16,17 @@ <%include file="../../python_stretch.include"/> - RUN apt-get update && apt-get -t testing install -y python3.6 python3-all-dev - RUN curl https://bootstrap.pypa.io/get-pip.py | python3.6 + RUN apt-get install -y jq zlib1g-dev libssl-dev + + RUN apt-get install -y jq build-essential libffi-dev + + RUN cd /tmp && ${'\\'} + wget -q https://github.com/python/cpython/archive/v3.6.9.tar.gz && ${'\\'} + tar xzvf v3.6.9.tar.gz && ${'\\'} + cd cpython-3.6.9 && ${'\\'} + ./configure && ${'\\'} + make install + + RUN python3.6 -m ensurepip && ${'\\'} + python3.6 -m pip install coverage + diff --git a/templates/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile.template b/templates/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile.template index c3602f6c512..c4270bdfc89 100644 --- a/templates/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile.template @@ -16,7 +16,7 @@ <%include file="../../python_stretch.include"/> - RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev + RUN apt-get update && apt-get -t buster install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 # for Python test coverage reporting diff --git a/templates/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile.template b/templates/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile.template index 8f2585a4d59..841a7f51b51 100644 --- a/templates/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile.template @@ -18,11 +18,14 @@ <%include file="../../python_stretch.include"/> RUN apt-get install -y jq zlib1g-dev libssl-dev - COPY get_cpython.sh /tmp - RUN apt-get install -y jq build-essential libffi-dev && ${'\\'} - chmod +x /tmp/get_cpython.sh && ${'\\'} - /tmp/get_cpython.sh && ${'\\'} - rm /tmp/get_cpython.sh + RUN apt-get install -y jq build-essential libffi-dev + + RUN cd /tmp && ${'\\'} + wget -q https://github.com/python/cpython/archive/v3.8.0b3.tar.gz && ${'\\'} + tar xzvf v3.8.0b3.tar.gz && ${'\\'} + cd cpython-3.8.0b3 && ${'\\'} + ./configure && ${'\\'} + make install RUN python3.8 -m ensurepip && ${'\\'} python3.8 -m pip install coverage diff --git a/templates/tools/dockerfile/test/sanity/Dockerfile.template b/templates/tools/dockerfile/test/sanity/Dockerfile.template index 2e4bdf537b7..84a4049be0e 100644 --- a/templates/tools/dockerfile/test/sanity/Dockerfile.template +++ b/templates/tools/dockerfile/test/sanity/Dockerfile.template @@ -18,7 +18,7 @@ <%include file="../../cxx_deps.include"/> #======================== # Sanity test dependencies - RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev + RUN apt-get update && apt-get -t buster install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 # Make Python 3.7 the default Python 3 version RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1 diff --git a/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile index acad500f90c..b11a1a1aa31 100644 --- a/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_python/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins @@ -68,5 +67,5 @@ RUN mkdir /var/local/jenkins CMD ["bash"] -RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev +RUN apt-get update && apt-get -t stable install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 diff --git a/tools/dockerfile/test/python_stretch_2.7_x64/Dockerfile b/tools/dockerfile/test/python_stretch_2.7_x64/Dockerfile index a7a8174db48..92b18e740da 100644 --- a/tools/dockerfile/test/python_stretch_2.7_x64/Dockerfile +++ b/tools/dockerfile/test/python_stretch_2.7_x64/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins diff --git a/tools/dockerfile/test/python_stretch_3.5_x64/Dockerfile b/tools/dockerfile/test/python_stretch_3.5_x64/Dockerfile index 0e97e77e2fd..7a256edffb2 100644 --- a/tools/dockerfile/test/python_stretch_3.5_x64/Dockerfile +++ b/tools/dockerfile/test/python_stretch_3.5_x64/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins diff --git a/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile b/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile index 9b16b2d3a1d..f18af660488 100644 --- a/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile +++ b/tools/dockerfile/test/python_stretch_3.6_x64/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins @@ -68,5 +67,16 @@ RUN mkdir /var/local/jenkins CMD ["bash"] -RUN apt-get update && apt-get -t testing install -y python3.6 python3-all-dev -RUN curl https://bootstrap.pypa.io/get-pip.py | python3.6 +RUN apt-get install -y jq zlib1g-dev libssl-dev + +RUN apt-get install -y jq build-essential libffi-dev + +RUN cd /tmp && \ + wget -q https://github.com/python/cpython/archive/v3.6.9.tar.gz && \ + tar xzvf v3.6.9.tar.gz && \ + cd cpython-3.6.9 && \ + ./configure && \ + make install + +RUN python3.6 -m ensurepip && \ + python3.6 -m pip install coverage diff --git a/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile b/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile index 45291ffdcfc..46b6526dc69 100644 --- a/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile +++ b/tools/dockerfile/test/python_stretch_3.7_x64/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins @@ -68,7 +67,7 @@ RUN mkdir /var/local/jenkins CMD ["bash"] -RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev +RUN apt-get update && apt-get -t buster install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 # for Python test coverage reporting diff --git a/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile b/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile index d5ecbc7110a..495d86fd099 100644 --- a/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile +++ b/tools/dockerfile/test/python_stretch_3.8_x64/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins @@ -69,11 +68,14 @@ CMD ["bash"] RUN apt-get install -y jq zlib1g-dev libssl-dev -COPY get_cpython.sh /tmp -RUN apt-get install -y jq build-essential libffi-dev && \ - chmod +x /tmp/get_cpython.sh && \ - /tmp/get_cpython.sh && \ - rm /tmp/get_cpython.sh +RUN apt-get install -y jq build-essential libffi-dev + +RUN cd /tmp && \ + wget -q https://github.com/python/cpython/archive/v3.8.0b3.tar.gz && \ + tar xzvf v3.8.0b3.tar.gz && \ + cd cpython-3.8.0b3 && \ + ./configure && \ + make install RUN python3.8 -m ensurepip && \ python3.8 -m pip install coverage diff --git a/tools/dockerfile/test/python_stretch_3.8_x64/get_cpython.sh b/tools/dockerfile/test/python_stretch_3.8_x64/get_cpython.sh deleted file mode 100644 index e051e974b38..00000000000 --- a/tools/dockerfile/test/python_stretch_3.8_x64/get_cpython.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -# Copyright 2019 The gRPC Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -VERSION_REGEX="v3.8.*" -REPO="python/cpython" - -LATEST=$(curl -s https://api.github.com/repos/$REPO/tags | \ - jq -r '.[] | select(.name|test("'$VERSION_REGEX'")) | .name' \ - | sort | tail -n1) - -wget https://github.com/$REPO/archive/$LATEST.tar.gz -tar xzvf *.tar.gz -( cd cpython* - ./configure - make install -) diff --git a/tools/dockerfile/test/sanity/Dockerfile b/tools/dockerfile/test/sanity/Dockerfile index ca786e264ed..675378b305b 100644 --- a/tools/dockerfile/test/sanity/Dockerfile +++ b/tools/dockerfile/test/sanity/Dockerfile @@ -57,10 +57,9 @@ RUN pip install --upgrade google-api-python-client oauth2client RUN apt-get update && apt-get install -y python2.7 python-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python2.7 -# Add Debian 'testing' repository -RUN echo 'deb http://ftp.de.debian.org/debian testing main' >> /etc/apt/sources.list -RUN echo 'APT::Default-Release "stable";' | tee -a /etc/apt/apt.conf.d/00local - +# Add Debian 'buster' repository, we will need it for installing newer versions of python +RUN echo 'deb http://ftp.de.debian.org/debian buster main' >> /etc/apt/sources.list +RUN echo 'APT::Default-Release "stretch";' | tee -a /etc/apt/apt.conf.d/00local RUN mkdir /var/local/jenkins @@ -73,7 +72,7 @@ RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev c #======================== # Sanity test dependencies -RUN apt-get update && apt-get -t testing install -y python3.7 python3-all-dev +RUN apt-get update && apt-get -t buster install -y python3.7 python3-all-dev RUN curl https://bootstrap.pypa.io/get-pip.py | python3.7 # Make Python 3.7 the default Python 3 version RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1 From 732e2a1e90c30eec5611441b122ab4d17eb1f7fb Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Tue, 27 Aug 2019 15:53:47 -0700 Subject: [PATCH 40/57] Tune load reporter test --- test/cpp/server/load_reporter/load_reporter_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/cpp/server/load_reporter/load_reporter_test.cc b/test/cpp/server/load_reporter/load_reporter_test.cc index 9d2ebfb0b4f..1866286069e 100644 --- a/test/cpp/server/load_reporter/load_reporter_test.cc +++ b/test/cpp/server/load_reporter/load_reporter_test.cc @@ -172,9 +172,9 @@ class LbFeedbackTest : public LoadReporterTest { // TODO(juanlishen): The error is big because we use sleep(). It should be // much smaller when we use fake clock. ASSERT_THAT(static_cast(lb_feedback.calls_per_second()), - DoubleNear(expected_qps, expected_qps * 0.05)); + DoubleNear(expected_qps, expected_qps * 0.3)); ASSERT_THAT(static_cast(lb_feedback.errors_per_second()), - DoubleNear(expected_eps, expected_eps * 0.05)); + DoubleNear(expected_eps, expected_eps * 0.3)); gpr_log(GPR_INFO, "Verified LB feedback matches the samples of index [%lu, %lu).", start, start + count); From 2767accc1bd0daab44c4199422742e1cd8f56d8f Mon Sep 17 00:00:00 2001 From: Arjun Roy Date: Fri, 23 Aug 2019 14:49:26 -0700 Subject: [PATCH 41/57] Fixed init-order-fiasco for static slice table. Fixes init-order bug affecting https://github.com/grpc/grpc/issues/19819 which was first exposed by this commit: https://github.com/grpc/grpc/commit/857375a1420df184963ed83f638dd21ea359aa37 --- .../filters/client_channel/client_channel.cc | 4 +- .../transport/chttp2/transport/hpack_table.cc | 2 +- .../transport/chttp2/transport/hpack_table.h | 4 +- src/core/lib/slice/slice_intern.cc | 20 +- src/core/lib/slice/slice_internal.h | 2 +- src/core/lib/slice/slice_utils.h | 8 +- src/core/lib/surface/init.cc | 3 + src/core/lib/transport/metadata.cc | 8 +- src/core/lib/transport/static_metadata.cc | 1648 +++++++---------- src/core/lib/transport/static_metadata.h | 454 ++--- test/core/slice/slice_test.cc | 10 +- test/core/transport/metadata_test.cc | 2 +- test/core/transport/status_metadata_test.cc | 5 +- tools/codegen/core/gen_static_metadata.py | 214 ++- 14 files changed, 1152 insertions(+), 1232 deletions(-) diff --git a/src/core/ext/filters/client_channel/client_channel.cc b/src/core/ext/filters/client_channel/client_channel.cc index 429828b0241..60b99c39a7a 100644 --- a/src/core/ext/filters/client_channel/client_channel.cc +++ b/src/core/ext/filters/client_channel/client_channel.cc @@ -3163,8 +3163,8 @@ void CallData::AddRetriableSendInitialMetadataOp( SubchannelCallRetryState* retry_state, SubchannelCallBatchData* batch_data) { // Maps the number of retries to the corresponding metadata value slice. - static const grpc_slice* retry_count_strings[] = { - &GRPC_MDSTR_1, &GRPC_MDSTR_2, &GRPC_MDSTR_3, &GRPC_MDSTR_4}; + const grpc_slice* retry_count_strings[] = {&GRPC_MDSTR_1, &GRPC_MDSTR_2, + &GRPC_MDSTR_3, &GRPC_MDSTR_4}; // We need to make a copy of the metadata batch for each attempt, since // the filters in the subchannel stack may modify this batch, and we don't // want those modifications to be passed forward to subsequent attempts. diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.cc b/src/core/ext/transport/chttp2/transport/hpack_table.cc index f86332c6bc3..68d3ec49fda 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.cc +++ b/src/core/ext/transport/chttp2/transport/hpack_table.cc @@ -189,7 +189,7 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - grpc_mdelem ent = grpc_static_mdelem_manifested[i]; + grpc_mdelem ent = grpc_static_mdelem_manifested()[i]; if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = i + 1u; r.has_value = grpc_slice_eq(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)); diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index 699b7eccaf2..a1aa77f5446 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -104,7 +104,7 @@ inline grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl* tbl, reading the core static metadata table here; at that point we'd need our own singleton static metadata in the correct order. */ return index <= GRPC_CHTTP2_LAST_STATIC_ENTRY - ? grpc_static_mdelem_manifested[index - 1] + ? grpc_static_mdelem_manifested()[index - 1] : grpc_chttp2_hptbl_lookup_dynamic_index(tbl, index); } /* add a table entry to the index */ @@ -120,7 +120,7 @@ size_t grpc_chttp2_get_size_in_hpack_table(grpc_mdelem elem, inline uintptr_t grpc_chttp2_get_static_hpack_table_index(grpc_mdelem md) { uintptr_t index = reinterpret_cast(GRPC_MDELEM_DATA(md)) - - grpc_static_mdelem_table; + grpc_static_mdelem_table(); if (index < GRPC_CHTTP2_LAST_STATIC_ENTRY) { return index + 1; // Hpack static metadata element indices start at 1 } diff --git a/src/core/lib/slice/slice_intern.cc b/src/core/lib/slice/slice_intern.cc index 13fe1ab40e9..d813e5195ad 100644 --- a/src/core/lib/slice/slice_intern.cc +++ b/src/core/lib/slice/slice_intern.cc @@ -138,11 +138,12 @@ grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { static_metadata_hash_ent ent = static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; + const grpc_core::StaticMetadataSlice* static_slice_table = + grpc_static_slice_table(); if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - grpc_slice_eq_static_interned(slice, - grpc_static_slice_table[ent.idx])) { + grpc_slice_eq_static_interned(slice, static_slice_table[ent.idx])) { *returned_slice_is_different = true; - return grpc_static_slice_table[ent.idx]; + return static_slice_table[ent.idx]; } } @@ -168,10 +169,11 @@ static const grpc_core::StaticMetadataSlice* MatchStaticSlice( for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { static_metadata_hash_ent ent = static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; + const grpc_core::StaticMetadataSlice* static_slice_table = + grpc_static_slice_table(); if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - grpc_static_slice_table[ent.idx].Equals( - std::forward(args)...)) { - return &grpc_static_slice_table[ent.idx]; + static_slice_table[ent.idx].Equals(std::forward(args)...)) { + return &static_slice_table[ent.idx]; } } return nullptr; @@ -318,9 +320,11 @@ void grpc_slice_intern_init(void) { static_metadata_hash[i].idx = GRPC_STATIC_MDSTR_COUNT; } max_static_metadata_hash_probe = 0; + const grpc_core::StaticMetadataSlice* static_slice_table = + grpc_static_slice_table(); for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { grpc_static_metadata_hash_values[i] = - grpc_slice_default_hash_internal(grpc_static_slice_table[i]); + grpc_slice_default_hash_internal(static_slice_table[i]); for (size_t j = 0; j < GPR_ARRAY_SIZE(static_metadata_hash); j++) { size_t slot = (grpc_static_metadata_hash_values[i] + j) % GPR_ARRAY_SIZE(static_metadata_hash); @@ -336,7 +340,7 @@ void grpc_slice_intern_init(void) { } // Handle KV hash for all static mdelems. for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; ++i) { - grpc_static_mdelem_table[i].HashInit(); + grpc_static_mdelem_table()[i].HashInit(); } } diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index e61f57c01ab..49ad15d5a56 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -182,7 +182,7 @@ struct StaticSliceRefcount { index(index) {} grpc_slice_refcount base; - uint32_t index; + const uint32_t index; }; extern grpc_slice_refcount kNoopRefcount; diff --git a/src/core/lib/slice/slice_utils.h b/src/core/lib/slice/slice_utils.h index e80de6d2ece..a4e19a9a61b 100644 --- a/src/core/lib/slice/slice_utils.h +++ b/src/core/lib/slice/slice_utils.h @@ -153,10 +153,14 @@ struct ExternallyManagedSlice : public UnmanagedMemorySlice { }; struct StaticMetadataSlice : public ManagedMemorySlice { - StaticMetadataSlice(grpc_slice_refcount* ref, size_t length, uint8_t* bytes) { + StaticMetadataSlice(grpc_slice_refcount* ref, size_t length, + const uint8_t* bytes) { refcount = ref; data.refcounted.length = length; - data.refcounted.bytes = bytes; + // NB: grpc_slice may or may not point to a static slice, but we are + // definitely pointing to static data here. Since we are not changing + // the underlying C-type, we need a const_cast here. + data.refcounted.bytes = const_cast(bytes); } }; diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 2a6d307ddab..c02b4021763 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -134,6 +134,7 @@ void grpc_init(void) { grpc_core::Fork::GlobalInit(); grpc_fork_handlers_auto_register(); grpc_stats_init(); + grpc_init_static_metadata_ctx(); grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); @@ -191,6 +192,8 @@ void grpc_shutdown_internal_locked(void) { grpc_core::ApplicationCallbackExecCtx::GlobalShutdown(); g_shutting_down = false; gpr_cv_broadcast(g_shutting_down_cv); + // Absolute last action will be to delete static metadata context. + grpc_destroy_static_metadata_ctx(); } void grpc_shutdown_internal(void* ignored) { diff --git a/src/core/lib/transport/metadata.cc b/src/core/lib/transport/metadata.cc index 4242923283e..76017207d47 100644 --- a/src/core/lib/transport/metadata.cc +++ b/src/core/lib/transport/metadata.cc @@ -269,9 +269,9 @@ void grpc_mdctx_global_shutdown() { #ifndef NDEBUG static int is_mdelem_static(grpc_mdelem e) { return reinterpret_cast(GRPC_MDELEM_DATA(e)) >= - &grpc_static_mdelem_table[0] && + &grpc_static_mdelem_table()[0] && reinterpret_cast(GRPC_MDELEM_DATA(e)) < - &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; + &grpc_static_mdelem_table()[GRPC_STATIC_MDELEM_COUNT]; } #endif @@ -569,7 +569,7 @@ void* grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void*)) { grpc_static_mdelem_user_data [reinterpret_cast( GRPC_MDELEM_DATA(md)) - - grpc_static_mdelem_table]); + grpc_static_mdelem_table()]); case GRPC_MDELEM_STORAGE_ALLOCATED: { auto* am = reinterpret_cast(GRPC_MDELEM_DATA(md)); return get_user_data(am->user_data(), destroy_func); @@ -611,7 +611,7 @@ void* grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void*), grpc_static_mdelem_user_data [reinterpret_cast( GRPC_MDELEM_DATA(md)) - - grpc_static_mdelem_table]); + grpc_static_mdelem_table()]); case GRPC_MDELEM_STORAGE_ALLOCATED: { auto* am = reinterpret_cast(GRPC_MDELEM_DATA(md)); return set_user_data(am->user_data(), destroy_func, data); diff --git a/src/core/lib/transport/static_metadata.cc b/src/core/lib/transport/static_metadata.cc index e2e618726f1..e43c17f1ca5 100644 --- a/src/core/lib/transport/static_metadata.cc +++ b/src/core/lib/transport/static_metadata.cc @@ -30,7 +30,7 @@ #include "src/core/lib/slice/slice_internal.h" -static uint8_t g_bytes[] = { +static constexpr uint8_t g_bytes[] = { 58, 112, 97, 116, 104, 58, 109, 101, 116, 104, 111, 100, 58, 115, 116, 97, 116, 117, 115, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 58, 115, 99, 104, 101, 109, 101, 116, 101, 103, 114, 112, 99, 45, 109, 101, @@ -125,774 +125,1055 @@ static uint8_t g_bytes[] = { 112}; grpc_slice_refcount grpc_core::StaticSliceRefcount::kStaticSubRefcount; -grpc_core::StaticSliceRefcount - grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = { - grpc_core::StaticSliceRefcount(0), - grpc_core::StaticSliceRefcount(1), - grpc_core::StaticSliceRefcount(2), - grpc_core::StaticSliceRefcount(3), - grpc_core::StaticSliceRefcount(4), - grpc_core::StaticSliceRefcount(5), - grpc_core::StaticSliceRefcount(6), - grpc_core::StaticSliceRefcount(7), - grpc_core::StaticSliceRefcount(8), - grpc_core::StaticSliceRefcount(9), - grpc_core::StaticSliceRefcount(10), - grpc_core::StaticSliceRefcount(11), - grpc_core::StaticSliceRefcount(12), - grpc_core::StaticSliceRefcount(13), - grpc_core::StaticSliceRefcount(14), - grpc_core::StaticSliceRefcount(15), - grpc_core::StaticSliceRefcount(16), - grpc_core::StaticSliceRefcount(17), - grpc_core::StaticSliceRefcount(18), - grpc_core::StaticSliceRefcount(19), - grpc_core::StaticSliceRefcount(20), - grpc_core::StaticSliceRefcount(21), - grpc_core::StaticSliceRefcount(22), - grpc_core::StaticSliceRefcount(23), - grpc_core::StaticSliceRefcount(24), - grpc_core::StaticSliceRefcount(25), - grpc_core::StaticSliceRefcount(26), - grpc_core::StaticSliceRefcount(27), - grpc_core::StaticSliceRefcount(28), - grpc_core::StaticSliceRefcount(29), - grpc_core::StaticSliceRefcount(30), - grpc_core::StaticSliceRefcount(31), - grpc_core::StaticSliceRefcount(32), - grpc_core::StaticSliceRefcount(33), - grpc_core::StaticSliceRefcount(34), - grpc_core::StaticSliceRefcount(35), - grpc_core::StaticSliceRefcount(36), - grpc_core::StaticSliceRefcount(37), - grpc_core::StaticSliceRefcount(38), - grpc_core::StaticSliceRefcount(39), - grpc_core::StaticSliceRefcount(40), - grpc_core::StaticSliceRefcount(41), - grpc_core::StaticSliceRefcount(42), - grpc_core::StaticSliceRefcount(43), - grpc_core::StaticSliceRefcount(44), - grpc_core::StaticSliceRefcount(45), - grpc_core::StaticSliceRefcount(46), - grpc_core::StaticSliceRefcount(47), - grpc_core::StaticSliceRefcount(48), - grpc_core::StaticSliceRefcount(49), - grpc_core::StaticSliceRefcount(50), - grpc_core::StaticSliceRefcount(51), - grpc_core::StaticSliceRefcount(52), - grpc_core::StaticSliceRefcount(53), - grpc_core::StaticSliceRefcount(54), - grpc_core::StaticSliceRefcount(55), - grpc_core::StaticSliceRefcount(56), - grpc_core::StaticSliceRefcount(57), - grpc_core::StaticSliceRefcount(58), - grpc_core::StaticSliceRefcount(59), - grpc_core::StaticSliceRefcount(60), - grpc_core::StaticSliceRefcount(61), - grpc_core::StaticSliceRefcount(62), - grpc_core::StaticSliceRefcount(63), - grpc_core::StaticSliceRefcount(64), - grpc_core::StaticSliceRefcount(65), - grpc_core::StaticSliceRefcount(66), - grpc_core::StaticSliceRefcount(67), - grpc_core::StaticSliceRefcount(68), - grpc_core::StaticSliceRefcount(69), - grpc_core::StaticSliceRefcount(70), - grpc_core::StaticSliceRefcount(71), - grpc_core::StaticSliceRefcount(72), - grpc_core::StaticSliceRefcount(73), - grpc_core::StaticSliceRefcount(74), - grpc_core::StaticSliceRefcount(75), - grpc_core::StaticSliceRefcount(76), - grpc_core::StaticSliceRefcount(77), - grpc_core::StaticSliceRefcount(78), - grpc_core::StaticSliceRefcount(79), - grpc_core::StaticSliceRefcount(80), - grpc_core::StaticSliceRefcount(81), - grpc_core::StaticSliceRefcount(82), - grpc_core::StaticSliceRefcount(83), - grpc_core::StaticSliceRefcount(84), - grpc_core::StaticSliceRefcount(85), - grpc_core::StaticSliceRefcount(86), - grpc_core::StaticSliceRefcount(87), - grpc_core::StaticSliceRefcount(88), - grpc_core::StaticSliceRefcount(89), - grpc_core::StaticSliceRefcount(90), - grpc_core::StaticSliceRefcount(91), - grpc_core::StaticSliceRefcount(92), - grpc_core::StaticSliceRefcount(93), - grpc_core::StaticSliceRefcount(94), - grpc_core::StaticSliceRefcount(95), - grpc_core::StaticSliceRefcount(96), - grpc_core::StaticSliceRefcount(97), - grpc_core::StaticSliceRefcount(98), - grpc_core::StaticSliceRefcount(99), - grpc_core::StaticSliceRefcount(100), - grpc_core::StaticSliceRefcount(101), - grpc_core::StaticSliceRefcount(102), - grpc_core::StaticSliceRefcount(103), - grpc_core::StaticSliceRefcount(104), - grpc_core::StaticSliceRefcount(105), - grpc_core::StaticSliceRefcount(106), - grpc_core::StaticSliceRefcount(107), -}; -const grpc_core::StaticMetadataSlice - grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[0].base, - 5, g_bytes + 0), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[1].base, - 7, g_bytes + 5), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[3].base, - 10, g_bytes + 19), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[4].base, - 7, g_bytes + 29), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[5].base, - 2, g_bytes + 36), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[6].base, - 12, g_bytes + 38), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[7].base, - 11, g_bytes + 50), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[8].base, - 16, g_bytes + 61), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[9].base, - 13, g_bytes + 77), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[11].base, - 21, g_bytes + 110), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[12].base, - 13, g_bytes + 131), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[13].base, - 14, g_bytes + 144), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[14].base, - 12, g_bytes + 158), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[15].base, - 16, g_bytes + 170), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[17].base, - 30, g_bytes + 201), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[18].base, - 37, g_bytes + 231), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[19].base, - 10, g_bytes + 268), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[20].base, - 4, g_bytes + 278), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[21].base, - 26, g_bytes + 282), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[22].base, - 22, g_bytes + 308), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[23].base, - 12, g_bytes + 330), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[24].base, - 1, g_bytes + 342), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[25].base, - 1, g_bytes + 343), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[26].base, - 1, g_bytes + 344), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[27].base, - 1, g_bytes + 345), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[29].base, - 19, g_bytes + 346), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[30].base, - 12, g_bytes + 365), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[31].base, - 30, g_bytes + 377), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[32].base, - 31, g_bytes + 407), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[33].base, - 36, g_bytes + 438), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[34].base, - 65, g_bytes + 474), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[35].base, - 54, g_bytes + 539), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[36].base, - 28, g_bytes + 593), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[37].base, - 80, g_bytes + 621), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[38].base, - 7, g_bytes + 701), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[39].base, - 4, g_bytes + 708), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[40].base, - 11, g_bytes + 712), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[41].base, - 3, g_bytes + 723), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[42].base, - 4, g_bytes + 726), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[43].base, - 1, g_bytes + 730), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[44].base, - 11, g_bytes + 731), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[45].base, - 4, g_bytes + 742), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[46].base, - 5, g_bytes + 746), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[47].base, - 3, g_bytes + 751), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[48].base, - 3, g_bytes + 754), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[49].base, - 3, g_bytes + 757), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[50].base, - 3, g_bytes + 760), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[51].base, - 3, g_bytes + 763), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[52].base, - 3, g_bytes + 766), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[53].base, - 3, g_bytes + 769), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[54].base, - 14, g_bytes + 772), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[55].base, - 13, g_bytes + 786), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[56].base, - 15, g_bytes + 799), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[57].base, - 13, g_bytes + 814), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[58].base, - 6, g_bytes + 827), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[59].base, - 27, g_bytes + 833), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[60].base, - 3, g_bytes + 860), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[61].base, - 5, g_bytes + 863), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[62].base, - 13, g_bytes + 868), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[63].base, - 13, g_bytes + 881), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[64].base, - 19, g_bytes + 894), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[65].base, - 16, g_bytes + 913), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[66].base, - 14, g_bytes + 929), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[67].base, - 16, g_bytes + 943), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[68].base, - 13, g_bytes + 959), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[69].base, - 6, g_bytes + 972), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[70].base, - 4, g_bytes + 978), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[71].base, - 4, g_bytes + 982), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[72].base, - 6, g_bytes + 986), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[73].base, - 7, g_bytes + 992), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[74].base, - 4, g_bytes + 999), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[75].base, - 8, g_bytes + 1003), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[76].base, - 17, g_bytes + 1011), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[77].base, - 13, g_bytes + 1028), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[78].base, - 8, g_bytes + 1041), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[79].base, - 19, g_bytes + 1049), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[80].base, - 13, g_bytes + 1068), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[81].base, - 4, g_bytes + 1081), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[82].base, - 8, g_bytes + 1085), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[83].base, - 12, g_bytes + 1093), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[84].base, - 18, g_bytes + 1105), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[85].base, - 19, g_bytes + 1123), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[86].base, - 5, g_bytes + 1142), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[87].base, - 7, g_bytes + 1147), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[88].base, - 7, g_bytes + 1154), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[89].base, - 11, g_bytes + 1161), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[90].base, - 6, g_bytes + 1172), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[91].base, - 10, g_bytes + 1178), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[92].base, - 25, g_bytes + 1188), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[93].base, - 17, g_bytes + 1213), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[94].base, - 4, g_bytes + 1230), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[95].base, - 3, g_bytes + 1234), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[96].base, - 16, g_bytes + 1237), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[97].base, - 1, g_bytes + 1253), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[98].base, - 8, g_bytes + 1254), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[99].base, - 8, g_bytes + 1262), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[100].base, 16, g_bytes + 1270), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[101].base, 4, g_bytes + 1286), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[102].base, 3, g_bytes + 1290), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[103].base, 11, g_bytes + 1293), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[104].base, 16, g_bytes + 1304), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[105].base, 13, g_bytes + 1320), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[106].base, 12, g_bytes + 1333), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[107].base, 21, g_bytes + 1345), -}; +namespace grpc_core { +struct StaticMetadataCtx { +#ifndef NDEBUG + const uint64_t init_canary = kGrpcStaticMetadataInitCanary; +#endif + StaticSliceRefcount refcounts[GRPC_STATIC_MDSTR_COUNT] = { + + StaticSliceRefcount(0), StaticSliceRefcount(1), + StaticSliceRefcount(2), StaticSliceRefcount(3), + StaticSliceRefcount(4), StaticSliceRefcount(5), + StaticSliceRefcount(6), StaticSliceRefcount(7), + StaticSliceRefcount(8), StaticSliceRefcount(9), + StaticSliceRefcount(10), StaticSliceRefcount(11), + StaticSliceRefcount(12), StaticSliceRefcount(13), + StaticSliceRefcount(14), StaticSliceRefcount(15), + StaticSliceRefcount(16), StaticSliceRefcount(17), + StaticSliceRefcount(18), StaticSliceRefcount(19), + StaticSliceRefcount(20), StaticSliceRefcount(21), + StaticSliceRefcount(22), StaticSliceRefcount(23), + StaticSliceRefcount(24), StaticSliceRefcount(25), + StaticSliceRefcount(26), StaticSliceRefcount(27), + StaticSliceRefcount(28), StaticSliceRefcount(29), + StaticSliceRefcount(30), StaticSliceRefcount(31), + StaticSliceRefcount(32), StaticSliceRefcount(33), + StaticSliceRefcount(34), StaticSliceRefcount(35), + StaticSliceRefcount(36), StaticSliceRefcount(37), + StaticSliceRefcount(38), StaticSliceRefcount(39), + StaticSliceRefcount(40), StaticSliceRefcount(41), + StaticSliceRefcount(42), StaticSliceRefcount(43), + StaticSliceRefcount(44), StaticSliceRefcount(45), + StaticSliceRefcount(46), StaticSliceRefcount(47), + StaticSliceRefcount(48), StaticSliceRefcount(49), + StaticSliceRefcount(50), StaticSliceRefcount(51), + StaticSliceRefcount(52), StaticSliceRefcount(53), + StaticSliceRefcount(54), StaticSliceRefcount(55), + StaticSliceRefcount(56), StaticSliceRefcount(57), + StaticSliceRefcount(58), StaticSliceRefcount(59), + StaticSliceRefcount(60), StaticSliceRefcount(61), + StaticSliceRefcount(62), StaticSliceRefcount(63), + StaticSliceRefcount(64), StaticSliceRefcount(65), + StaticSliceRefcount(66), StaticSliceRefcount(67), + StaticSliceRefcount(68), StaticSliceRefcount(69), + StaticSliceRefcount(70), StaticSliceRefcount(71), + StaticSliceRefcount(72), StaticSliceRefcount(73), + StaticSliceRefcount(74), StaticSliceRefcount(75), + StaticSliceRefcount(76), StaticSliceRefcount(77), + StaticSliceRefcount(78), StaticSliceRefcount(79), + StaticSliceRefcount(80), StaticSliceRefcount(81), + StaticSliceRefcount(82), StaticSliceRefcount(83), + StaticSliceRefcount(84), StaticSliceRefcount(85), + StaticSliceRefcount(86), StaticSliceRefcount(87), + StaticSliceRefcount(88), StaticSliceRefcount(89), + StaticSliceRefcount(90), StaticSliceRefcount(91), + StaticSliceRefcount(92), StaticSliceRefcount(93), + StaticSliceRefcount(94), StaticSliceRefcount(95), + StaticSliceRefcount(96), StaticSliceRefcount(97), + StaticSliceRefcount(98), StaticSliceRefcount(99), + StaticSliceRefcount(100), StaticSliceRefcount(101), + StaticSliceRefcount(102), StaticSliceRefcount(103), + StaticSliceRefcount(104), StaticSliceRefcount(105), + StaticSliceRefcount(106), StaticSliceRefcount(107), + }; + + const StaticMetadataSlice slices[GRPC_STATIC_MDSTR_COUNT] = { -/* Warning: the core static metadata currently operates under the soft -constraint that the first GRPC_CHTTP2_LAST_STATIC_ENTRY (61) entries must -contain metadata specified by the http2 hpack standard. The CHTTP2 transport -reads the core metadata with this assumption in mind. If the order of the core -static metadata is to be changed, then the CHTTP2 transport must be changed as -well to stop relying on the core metadata. */ + grpc_core::StaticMetadataSlice(&refcounts[0].base, 5, g_bytes + 0), + grpc_core::StaticMetadataSlice(&refcounts[1].base, 7, g_bytes + 5), + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[3].base, 10, g_bytes + 19), + grpc_core::StaticMetadataSlice(&refcounts[4].base, 7, g_bytes + 29), + grpc_core::StaticMetadataSlice(&refcounts[5].base, 2, g_bytes + 36), + grpc_core::StaticMetadataSlice(&refcounts[6].base, 12, g_bytes + 38), + grpc_core::StaticMetadataSlice(&refcounts[7].base, 11, g_bytes + 50), + grpc_core::StaticMetadataSlice(&refcounts[8].base, 16, g_bytes + 61), + grpc_core::StaticMetadataSlice(&refcounts[9].base, 13, g_bytes + 77), + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[11].base, 21, g_bytes + 110), + grpc_core::StaticMetadataSlice(&refcounts[12].base, 13, g_bytes + 131), + grpc_core::StaticMetadataSlice(&refcounts[13].base, 14, g_bytes + 144), + grpc_core::StaticMetadataSlice(&refcounts[14].base, 12, g_bytes + 158), + grpc_core::StaticMetadataSlice(&refcounts[15].base, 16, g_bytes + 170), + grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[17].base, 30, g_bytes + 201), + grpc_core::StaticMetadataSlice(&refcounts[18].base, 37, g_bytes + 231), + grpc_core::StaticMetadataSlice(&refcounts[19].base, 10, g_bytes + 268), + grpc_core::StaticMetadataSlice(&refcounts[20].base, 4, g_bytes + 278), + grpc_core::StaticMetadataSlice(&refcounts[21].base, 26, g_bytes + 282), + grpc_core::StaticMetadataSlice(&refcounts[22].base, 22, g_bytes + 308), + grpc_core::StaticMetadataSlice(&refcounts[23].base, 12, g_bytes + 330), + grpc_core::StaticMetadataSlice(&refcounts[24].base, 1, g_bytes + 342), + grpc_core::StaticMetadataSlice(&refcounts[25].base, 1, g_bytes + 343), + grpc_core::StaticMetadataSlice(&refcounts[26].base, 1, g_bytes + 344), + grpc_core::StaticMetadataSlice(&refcounts[27].base, 1, g_bytes + 345), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + grpc_core::StaticMetadataSlice(&refcounts[29].base, 19, g_bytes + 346), + grpc_core::StaticMetadataSlice(&refcounts[30].base, 12, g_bytes + 365), + grpc_core::StaticMetadataSlice(&refcounts[31].base, 30, g_bytes + 377), + grpc_core::StaticMetadataSlice(&refcounts[32].base, 31, g_bytes + 407), + grpc_core::StaticMetadataSlice(&refcounts[33].base, 36, g_bytes + 438), + grpc_core::StaticMetadataSlice(&refcounts[34].base, 65, g_bytes + 474), + grpc_core::StaticMetadataSlice(&refcounts[35].base, 54, g_bytes + 539), + grpc_core::StaticMetadataSlice(&refcounts[36].base, 28, g_bytes + 593), + grpc_core::StaticMetadataSlice(&refcounts[37].base, 80, g_bytes + 621), + grpc_core::StaticMetadataSlice(&refcounts[38].base, 7, g_bytes + 701), + grpc_core::StaticMetadataSlice(&refcounts[39].base, 4, g_bytes + 708), + grpc_core::StaticMetadataSlice(&refcounts[40].base, 11, g_bytes + 712), + grpc_core::StaticMetadataSlice(&refcounts[41].base, 3, g_bytes + 723), + grpc_core::StaticMetadataSlice(&refcounts[42].base, 4, g_bytes + 726), + grpc_core::StaticMetadataSlice(&refcounts[43].base, 1, g_bytes + 730), + grpc_core::StaticMetadataSlice(&refcounts[44].base, 11, g_bytes + 731), + grpc_core::StaticMetadataSlice(&refcounts[45].base, 4, g_bytes + 742), + grpc_core::StaticMetadataSlice(&refcounts[46].base, 5, g_bytes + 746), + grpc_core::StaticMetadataSlice(&refcounts[47].base, 3, g_bytes + 751), + grpc_core::StaticMetadataSlice(&refcounts[48].base, 3, g_bytes + 754), + grpc_core::StaticMetadataSlice(&refcounts[49].base, 3, g_bytes + 757), + grpc_core::StaticMetadataSlice(&refcounts[50].base, 3, g_bytes + 760), + grpc_core::StaticMetadataSlice(&refcounts[51].base, 3, g_bytes + 763), + grpc_core::StaticMetadataSlice(&refcounts[52].base, 3, g_bytes + 766), + grpc_core::StaticMetadataSlice(&refcounts[53].base, 3, g_bytes + 769), + grpc_core::StaticMetadataSlice(&refcounts[54].base, 14, g_bytes + 772), + grpc_core::StaticMetadataSlice(&refcounts[55].base, 13, g_bytes + 786), + grpc_core::StaticMetadataSlice(&refcounts[56].base, 15, g_bytes + 799), + grpc_core::StaticMetadataSlice(&refcounts[57].base, 13, g_bytes + 814), + grpc_core::StaticMetadataSlice(&refcounts[58].base, 6, g_bytes + 827), + grpc_core::StaticMetadataSlice(&refcounts[59].base, 27, g_bytes + 833), + grpc_core::StaticMetadataSlice(&refcounts[60].base, 3, g_bytes + 860), + grpc_core::StaticMetadataSlice(&refcounts[61].base, 5, g_bytes + 863), + grpc_core::StaticMetadataSlice(&refcounts[62].base, 13, g_bytes + 868), + grpc_core::StaticMetadataSlice(&refcounts[63].base, 13, g_bytes + 881), + grpc_core::StaticMetadataSlice(&refcounts[64].base, 19, g_bytes + 894), + grpc_core::StaticMetadataSlice(&refcounts[65].base, 16, g_bytes + 913), + grpc_core::StaticMetadataSlice(&refcounts[66].base, 14, g_bytes + 929), + grpc_core::StaticMetadataSlice(&refcounts[67].base, 16, g_bytes + 943), + grpc_core::StaticMetadataSlice(&refcounts[68].base, 13, g_bytes + 959), + grpc_core::StaticMetadataSlice(&refcounts[69].base, 6, g_bytes + 972), + grpc_core::StaticMetadataSlice(&refcounts[70].base, 4, g_bytes + 978), + grpc_core::StaticMetadataSlice(&refcounts[71].base, 4, g_bytes + 982), + grpc_core::StaticMetadataSlice(&refcounts[72].base, 6, g_bytes + 986), + grpc_core::StaticMetadataSlice(&refcounts[73].base, 7, g_bytes + 992), + grpc_core::StaticMetadataSlice(&refcounts[74].base, 4, g_bytes + 999), + grpc_core::StaticMetadataSlice(&refcounts[75].base, 8, g_bytes + 1003), + grpc_core::StaticMetadataSlice(&refcounts[76].base, 17, g_bytes + 1011), + grpc_core::StaticMetadataSlice(&refcounts[77].base, 13, g_bytes + 1028), + grpc_core::StaticMetadataSlice(&refcounts[78].base, 8, g_bytes + 1041), + grpc_core::StaticMetadataSlice(&refcounts[79].base, 19, g_bytes + 1049), + grpc_core::StaticMetadataSlice(&refcounts[80].base, 13, g_bytes + 1068), + grpc_core::StaticMetadataSlice(&refcounts[81].base, 4, g_bytes + 1081), + grpc_core::StaticMetadataSlice(&refcounts[82].base, 8, g_bytes + 1085), + grpc_core::StaticMetadataSlice(&refcounts[83].base, 12, g_bytes + 1093), + grpc_core::StaticMetadataSlice(&refcounts[84].base, 18, g_bytes + 1105), + grpc_core::StaticMetadataSlice(&refcounts[85].base, 19, g_bytes + 1123), + grpc_core::StaticMetadataSlice(&refcounts[86].base, 5, g_bytes + 1142), + grpc_core::StaticMetadataSlice(&refcounts[87].base, 7, g_bytes + 1147), + grpc_core::StaticMetadataSlice(&refcounts[88].base, 7, g_bytes + 1154), + grpc_core::StaticMetadataSlice(&refcounts[89].base, 11, g_bytes + 1161), + grpc_core::StaticMetadataSlice(&refcounts[90].base, 6, g_bytes + 1172), + grpc_core::StaticMetadataSlice(&refcounts[91].base, 10, g_bytes + 1178), + grpc_core::StaticMetadataSlice(&refcounts[92].base, 25, g_bytes + 1188), + grpc_core::StaticMetadataSlice(&refcounts[93].base, 17, g_bytes + 1213), + grpc_core::StaticMetadataSlice(&refcounts[94].base, 4, g_bytes + 1230), + grpc_core::StaticMetadataSlice(&refcounts[95].base, 3, g_bytes + 1234), + grpc_core::StaticMetadataSlice(&refcounts[96].base, 16, g_bytes + 1237), + grpc_core::StaticMetadataSlice(&refcounts[97].base, 1, g_bytes + 1253), + grpc_core::StaticMetadataSlice(&refcounts[98].base, 8, g_bytes + 1254), + grpc_core::StaticMetadataSlice(&refcounts[99].base, 8, g_bytes + 1262), + grpc_core::StaticMetadataSlice(&refcounts[100].base, 16, g_bytes + 1270), + grpc_core::StaticMetadataSlice(&refcounts[101].base, 4, g_bytes + 1286), + grpc_core::StaticMetadataSlice(&refcounts[102].base, 3, g_bytes + 1290), + grpc_core::StaticMetadataSlice(&refcounts[103].base, 11, g_bytes + 1293), + grpc_core::StaticMetadataSlice(&refcounts[104].base, 16, g_bytes + 1304), + grpc_core::StaticMetadataSlice(&refcounts[105].base, 13, g_bytes + 1320), + grpc_core::StaticMetadataSlice(&refcounts[106].base, 12, g_bytes + 1333), + grpc_core::StaticMetadataSlice(&refcounts[107].base, 21, g_bytes + 1345), + }; + StaticMetadata static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[3].base, 10, g_bytes + 19), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 0), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[1].base, 7, g_bytes + 5), + grpc_core::StaticMetadataSlice(&refcounts[41].base, 3, g_bytes + 723), + 1), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[1].base, 7, g_bytes + 5), + grpc_core::StaticMetadataSlice(&refcounts[42].base, 4, g_bytes + 726), + 2), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[0].base, 5, g_bytes + 0), + grpc_core::StaticMetadataSlice(&refcounts[43].base, 1, g_bytes + 730), + 3), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[0].base, 5, g_bytes + 0), + grpc_core::StaticMetadataSlice(&refcounts[44].base, 11, + g_bytes + 731), + 4), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[4].base, 7, g_bytes + 29), + grpc_core::StaticMetadataSlice(&refcounts[45].base, 4, g_bytes + 742), + 5), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[4].base, 7, g_bytes + 29), + grpc_core::StaticMetadataSlice(&refcounts[46].base, 5, g_bytes + 746), + 6), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[47].base, 3, g_bytes + 751), + 7), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[48].base, 3, g_bytes + 754), + 8), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[49].base, 3, g_bytes + 757), + 9), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[50].base, 3, g_bytes + 760), + 10), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[51].base, 3, g_bytes + 763), + 11), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[52].base, 3, g_bytes + 766), + 12), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[2].base, 7, g_bytes + 12), + grpc_core::StaticMetadataSlice(&refcounts[53].base, 3, g_bytes + 769), + 13), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[54].base, 14, + g_bytes + 772), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 14), + StaticMetadata(grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, + g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[55].base, 13, + g_bytes + 786), + 15), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[56].base, 15, + g_bytes + 799), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 16), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[57].base, 13, + g_bytes + 814), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 17), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[58].base, 6, g_bytes + 827), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 18), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[59].base, 27, + g_bytes + 833), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 19), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[60].base, 3, g_bytes + 860), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 20), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[61].base, 5, g_bytes + 863), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 21), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[62].base, 13, + g_bytes + 868), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 22), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[63].base, 13, + g_bytes + 881), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 23), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[64].base, 19, + g_bytes + 894), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 24), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[15].base, 16, + g_bytes + 170), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 25), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[65].base, 16, + g_bytes + 913), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 26), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[66].base, 14, + g_bytes + 929), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 27), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[67].base, 16, + g_bytes + 943), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 28), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[68].base, 13, + g_bytes + 959), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 29), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[14].base, 12, + g_bytes + 158), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 30), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[69].base, 6, g_bytes + 972), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 31), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[70].base, 4, g_bytes + 978), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 32), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[71].base, 4, g_bytes + 982), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 33), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[72].base, 6, g_bytes + 986), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 34), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[73].base, 7, g_bytes + 992), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 35), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[74].base, 4, g_bytes + 999), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 36), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[20].base, 4, g_bytes + 278), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 37), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[75].base, 8, + g_bytes + 1003), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 38), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[76].base, 17, + g_bytes + 1011), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 39), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[77].base, 13, + g_bytes + 1028), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 40), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[78].base, 8, + g_bytes + 1041), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 41), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[79].base, 19, + g_bytes + 1049), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 42), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[80].base, 13, + g_bytes + 1068), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 43), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[81].base, 4, + g_bytes + 1081), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 44), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[82].base, 8, + g_bytes + 1085), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 45), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[83].base, 12, + g_bytes + 1093), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 46), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[84].base, 18, + g_bytes + 1105), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 47), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[85].base, 19, + g_bytes + 1123), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 48), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[86].base, 5, + g_bytes + 1142), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 49), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[87].base, 7, + g_bytes + 1147), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 50), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[88].base, 7, + g_bytes + 1154), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 51), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[89].base, 11, + g_bytes + 1161), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 52), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[90].base, 6, + g_bytes + 1172), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 53), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[91].base, 10, + g_bytes + 1178), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 54), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[92].base, 25, + g_bytes + 1188), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 55), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[93].base, 17, + g_bytes + 1213), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 56), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[19].base, 10, + g_bytes + 268), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 57), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[94].base, 4, + g_bytes + 1230), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 58), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[95].base, 3, + g_bytes + 1234), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 59), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[96].base, 16, + g_bytes + 1237), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 60), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[7].base, 11, g_bytes + 50), + grpc_core::StaticMetadataSlice(&refcounts[97].base, 1, + g_bytes + 1253), + 61), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[7].base, 11, g_bytes + 50), + grpc_core::StaticMetadataSlice(&refcounts[24].base, 1, g_bytes + 342), + 62), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[7].base, 11, g_bytes + 50), + grpc_core::StaticMetadataSlice(&refcounts[25].base, 1, g_bytes + 343), + 63), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[9].base, 13, g_bytes + 77), + grpc_core::StaticMetadataSlice(&refcounts[98].base, 8, + g_bytes + 1254), + 64), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[9].base, 13, g_bytes + 77), + grpc_core::StaticMetadataSlice(&refcounts[39].base, 4, g_bytes + 708), + 65), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[9].base, 13, g_bytes + 77), + grpc_core::StaticMetadataSlice(&refcounts[38].base, 7, g_bytes + 701), + 66), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[5].base, 2, g_bytes + 36), + grpc_core::StaticMetadataSlice(&refcounts[99].base, 8, + g_bytes + 1262), + 67), + StaticMetadata(grpc_core::StaticMetadataSlice(&refcounts[14].base, 12, + g_bytes + 158), + grpc_core::StaticMetadataSlice(&refcounts[100].base, 16, + g_bytes + 1270), + 68), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[4].base, 7, g_bytes + 29), + grpc_core::StaticMetadataSlice(&refcounts[101].base, 4, + g_bytes + 1286), + 69), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[1].base, 7, g_bytes + 5), + grpc_core::StaticMetadataSlice(&refcounts[102].base, 3, + g_bytes + 1290), + 70), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, + g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 71), + StaticMetadata(grpc_core::StaticMetadataSlice(&refcounts[15].base, 16, + g_bytes + 170), + grpc_core::StaticMetadataSlice(&refcounts[98].base, 8, + g_bytes + 1254), + 72), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[15].base, 16, + g_bytes + 170), + grpc_core::StaticMetadataSlice(&refcounts[39].base, 4, g_bytes + 708), + 73), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[103].base, 11, + g_bytes + 1293), + grpc_core::StaticMetadataSlice(&refcounts[28].base, 0, g_bytes + 346), + 74), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[98].base, 8, + g_bytes + 1254), + 75), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[38].base, 7, g_bytes + 701), + 76), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[104].base, 16, + g_bytes + 1304), + 77), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[39].base, 4, g_bytes + 708), + 78), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[105].base, 13, + g_bytes + 1320), + 79), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[106].base, 12, + g_bytes + 1333), + 80), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[10].base, 20, g_bytes + 90), + grpc_core::StaticMetadataSlice(&refcounts[107].base, 21, + g_bytes + 1345), + 81), + StaticMetadata(grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, + g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[98].base, 8, + g_bytes + 1254), + 82), + StaticMetadata( + grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, + g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[39].base, 4, g_bytes + 708), + 83), + StaticMetadata(grpc_core::StaticMetadataSlice(&refcounts[16].base, 15, + g_bytes + 186), + grpc_core::StaticMetadataSlice(&refcounts[105].base, 13, + g_bytes + 1320), + 84), + }; -grpc_mdelem grpc_static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT] = { - // clang-format off + /* Warning: the core static metadata currently operates under the soft + constraint that the first GRPC_CHTTP2_LAST_STATIC_ENTRY (61) entries must + contain metadata specified by the http2 hpack standard. The CHTTP2 transport + reads the core metadata with this assumption in mind. If the order of the core + static metadata is to be changed, then the CHTTP2 transport must be changed as + well to stop relying on the core metadata. */ + + grpc_mdelem static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT] = { + // clang-format off /* GRPC_MDELEM_AUTHORITY_EMPTY: ":authority": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[0].data(), + &static_mdelem_table[0].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_METHOD_GET: ":method": "GET" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[1].data(), + &static_mdelem_table[1].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_METHOD_POST: ":method": "POST" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[2].data(), + &static_mdelem_table[2].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_PATH_SLASH: ":path": "/" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[3].data(), + &static_mdelem_table[3].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML: ":path": "/index.html" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[4].data(), + &static_mdelem_table[4].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_SCHEME_HTTP: ":scheme": "http" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[5].data(), + &static_mdelem_table[5].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_SCHEME_HTTPS: ":scheme": "https" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[6].data(), + &static_mdelem_table[6].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_200: ":status": "200" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[7].data(), + &static_mdelem_table[7].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_204: ":status": "204" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[8].data(), + &static_mdelem_table[8].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_206: ":status": "206" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[9].data(), + &static_mdelem_table[9].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_304: ":status": "304" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[10].data(), + &static_mdelem_table[10].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_400: ":status": "400" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[11].data(), + &static_mdelem_table[11].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_404: ":status": "404" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[12].data(), + &static_mdelem_table[12].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STATUS_500: ":status": "500" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[13].data(), + &static_mdelem_table[13].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_CHARSET_EMPTY: "accept-charset": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[14].data(), + &static_mdelem_table[14].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE: "accept-encoding": "gzip, deflate" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[15].data(), + &static_mdelem_table[15].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY: "accept-language": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[16].data(), + &static_mdelem_table[16].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_RANGES_EMPTY: "accept-ranges": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[17].data(), + &static_mdelem_table[17].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_EMPTY: "accept": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[18].data(), + &static_mdelem_table[18].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY: "access-control-allow-origin": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[19].data(), + &static_mdelem_table[19].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_AGE_EMPTY: "age": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[20].data(), + &static_mdelem_table[20].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ALLOW_EMPTY: "allow": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[21].data(), + &static_mdelem_table[21].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_AUTHORIZATION_EMPTY: "authorization": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[22].data(), + &static_mdelem_table[22].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CACHE_CONTROL_EMPTY: "cache-control": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[23].data(), + &static_mdelem_table[23].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY: "content-disposition": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[24].data(), + &static_mdelem_table[24].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_ENCODING_EMPTY: "content-encoding": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[25].data(), + &static_mdelem_table[25].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY: "content-language": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[26].data(), + &static_mdelem_table[26].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_LENGTH_EMPTY: "content-length": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[27].data(), + &static_mdelem_table[27].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_LOCATION_EMPTY: "content-location": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[28].data(), + &static_mdelem_table[28].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_RANGE_EMPTY: "content-range": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[29].data(), + &static_mdelem_table[29].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_TYPE_EMPTY: "content-type": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[30].data(), + &static_mdelem_table[30].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_COOKIE_EMPTY: "cookie": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[31].data(), + &static_mdelem_table[31].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_DATE_EMPTY: "date": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[32].data(), + &static_mdelem_table[32].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ETAG_EMPTY: "etag": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[33].data(), + &static_mdelem_table[33].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_EXPECT_EMPTY: "expect": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[34].data(), + &static_mdelem_table[34].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_EXPIRES_EMPTY: "expires": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[35].data(), + &static_mdelem_table[35].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_FROM_EMPTY: "from": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[36].data(), + &static_mdelem_table[36].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_HOST_EMPTY: "host": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[37].data(), + &static_mdelem_table[37].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_IF_MATCH_EMPTY: "if-match": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[38].data(), + &static_mdelem_table[38].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY: "if-modified-since": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[39].data(), + &static_mdelem_table[39].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_IF_NONE_MATCH_EMPTY: "if-none-match": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[40].data(), + &static_mdelem_table[40].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_IF_RANGE_EMPTY: "if-range": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[41].data(), + &static_mdelem_table[41].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY: "if-unmodified-since": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[42].data(), + &static_mdelem_table[42].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_LAST_MODIFIED_EMPTY: "last-modified": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[43].data(), + &static_mdelem_table[43].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_LINK_EMPTY: "link": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[44].data(), + &static_mdelem_table[44].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_LOCATION_EMPTY: "location": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[45].data(), + &static_mdelem_table[45].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_MAX_FORWARDS_EMPTY: "max-forwards": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[46].data(), + &static_mdelem_table[46].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY: "proxy-authenticate": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[47].data(), + &static_mdelem_table[47].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY: "proxy-authorization": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[48].data(), + &static_mdelem_table[48].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_RANGE_EMPTY: "range": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[49].data(), + &static_mdelem_table[49].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_REFERER_EMPTY: "referer": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[50].data(), + &static_mdelem_table[50].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_REFRESH_EMPTY: "refresh": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[51].data(), + &static_mdelem_table[51].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_RETRY_AFTER_EMPTY: "retry-after": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[52].data(), + &static_mdelem_table[52].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_SERVER_EMPTY: "server": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[53].data(), + &static_mdelem_table[53].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_SET_COOKIE_EMPTY: "set-cookie": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[54].data(), + &static_mdelem_table[54].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY: "strict-transport-security": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[55].data(), + &static_mdelem_table[55].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_TRANSFER_ENCODING_EMPTY: "transfer-encoding": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[56].data(), + &static_mdelem_table[56].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_USER_AGENT_EMPTY: "user-agent": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[57].data(), + &static_mdelem_table[57].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_VARY_EMPTY: "vary": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[58].data(), + &static_mdelem_table[58].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_VIA_EMPTY: "via": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[59].data(), + &static_mdelem_table[59].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY: "www-authenticate": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[60].data(), + &static_mdelem_table[60].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_STATUS_0: "grpc-status": "0" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[61].data(), + &static_mdelem_table[61].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_STATUS_1: "grpc-status": "1" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[62].data(), + &static_mdelem_table[62].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_STATUS_2: "grpc-status": "2" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[63].data(), + &static_mdelem_table[63].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ENCODING_IDENTITY: "grpc-encoding": "identity" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[64].data(), + &static_mdelem_table[64].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ENCODING_GZIP: "grpc-encoding": "gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[65].data(), + &static_mdelem_table[65].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ENCODING_DEFLATE: "grpc-encoding": "deflate" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[66].data(), + &static_mdelem_table[66].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_TE_TRAILERS: "te": "trailers" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[67].data(), + &static_mdelem_table[67].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC: "content-type": "application/grpc" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[68].data(), + &static_mdelem_table[68].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_SCHEME_GRPC: ":scheme": "grpc" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[69].data(), + &static_mdelem_table[69].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_METHOD_PUT: ":method": "PUT" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[70].data(), + &static_mdelem_table[70].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_ENCODING_EMPTY: "accept-encoding": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[71].data(), + &static_mdelem_table[71].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_ENCODING_IDENTITY: "content-encoding": "identity" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[72].data(), + &static_mdelem_table[72].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_CONTENT_ENCODING_GZIP: "content-encoding": "gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[73].data(), + &static_mdelem_table[73].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_LB_COST_BIN_EMPTY: "lb-cost-bin": "" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[74].data(), + &static_mdelem_table[74].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY: "grpc-accept-encoding": "identity" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[75].data(), + &static_mdelem_table[75].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE: "grpc-accept-encoding": "deflate" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[76].data(), + &static_mdelem_table[76].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE: "grpc-accept-encoding": "identity,deflate" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[77].data(), + &static_mdelem_table[77].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP: "grpc-accept-encoding": "gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[78].data(), + &static_mdelem_table[78].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP: "grpc-accept-encoding": "identity,gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[79].data(), + &static_mdelem_table[79].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP: "grpc-accept-encoding": "deflate,gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[80].data(), + &static_mdelem_table[80].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP: "grpc-accept-encoding": "identity,deflate,gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[81].data(), + &static_mdelem_table[81].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_ENCODING_IDENTITY: "accept-encoding": "identity" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[82].data(), + &static_mdelem_table[82].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_ENCODING_GZIP: "accept-encoding": "gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[83].data(), + &static_mdelem_table[83].data(), GRPC_MDELEM_STORAGE_STATIC), /* GRPC_MDELEM_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP: "accept-encoding": "identity,gzip" */ GRPC_MAKE_MDELEM( - &grpc_static_mdelem_table[84].data(), + &static_mdelem_table[84].data(), GRPC_MDELEM_STORAGE_STATIC) - // clang-format on + // clang-format on + }; }; +} // namespace grpc_core + +namespace grpc_core { +static StaticMetadataCtx* g_static_metadata_slice_ctx = nullptr; +const StaticMetadataSlice* g_static_metadata_slice_table = nullptr; +StaticSliceRefcount* g_static_metadata_slice_refcounts = nullptr; +StaticMetadata* g_static_mdelem_table = nullptr; +grpc_mdelem* g_static_mdelem_manifested = nullptr; +#ifndef NDEBUG +uint64_t StaticMetadataInitCanary() { + return g_static_metadata_slice_ctx->init_canary; +} +#endif +} // namespace grpc_core + +void grpc_init_static_metadata_ctx(void) { + grpc_core::g_static_metadata_slice_ctx = + grpc_core::New(); + grpc_core::g_static_metadata_slice_table = + grpc_core::g_static_metadata_slice_ctx->slices; + grpc_core::g_static_metadata_slice_refcounts = + grpc_core::g_static_metadata_slice_ctx->refcounts; + grpc_core::g_static_mdelem_table = + grpc_core::g_static_metadata_slice_ctx->static_mdelem_table; + grpc_core::g_static_mdelem_manifested = + grpc_core::g_static_metadata_slice_ctx->static_mdelem_manifested; +} + +void grpc_destroy_static_metadata_ctx(void) { + grpc_core::Delete( + grpc_core::g_static_metadata_slice_ctx); + grpc_core::g_static_metadata_slice_ctx = nullptr; + grpc_core::g_static_metadata_slice_table = nullptr; + grpc_core::g_static_metadata_slice_refcounts = nullptr; + grpc_core::g_static_mdelem_table = nullptr; + grpc_core::g_static_mdelem_manifested = nullptr; +} + uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -946,523 +1227,12 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(intptr_t a, intptr_t b) { uint32_t h = elems_phash(k); return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k && elem_idxs[h] != 255 - ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]].data(), - GRPC_MDELEM_STORAGE_STATIC) + ? GRPC_MAKE_MDELEM( + &grpc_static_mdelem_table()[elem_idxs[h]].data(), + GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL; } -grpc_core::StaticMetadata grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[3].base, - 10, g_bytes + 19), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 0), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[1].base, - 7, g_bytes + 5), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[41].base, - 3, g_bytes + 723), - 1), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[1].base, - 7, g_bytes + 5), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[42].base, - 4, g_bytes + 726), - 2), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[0].base, - 5, g_bytes + 0), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[43].base, - 1, g_bytes + 730), - 3), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[0].base, - 5, g_bytes + 0), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[44].base, - 11, g_bytes + 731), - 4), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[4].base, - 7, g_bytes + 29), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[45].base, - 4, g_bytes + 742), - 5), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[4].base, - 7, g_bytes + 29), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[46].base, - 5, g_bytes + 746), - 6), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[47].base, - 3, g_bytes + 751), - 7), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[48].base, - 3, g_bytes + 754), - 8), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[49].base, - 3, g_bytes + 757), - 9), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[50].base, - 3, g_bytes + 760), - 10), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[51].base, - 3, g_bytes + 763), - 11), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[52].base, - 3, g_bytes + 766), - 12), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[2].base, - 7, g_bytes + 12), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[53].base, - 3, g_bytes + 769), - 13), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[54].base, - 14, g_bytes + 772), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 14), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[55].base, - 13, g_bytes + 786), - 15), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[56].base, - 15, g_bytes + 799), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 16), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[57].base, - 13, g_bytes + 814), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 17), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[58].base, - 6, g_bytes + 827), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 18), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[59].base, - 27, g_bytes + 833), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 19), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[60].base, - 3, g_bytes + 860), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 20), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[61].base, - 5, g_bytes + 863), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 21), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[62].base, - 13, g_bytes + 868), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 22), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[63].base, - 13, g_bytes + 881), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 23), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[64].base, - 19, g_bytes + 894), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 24), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[15].base, - 16, g_bytes + 170), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 25), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[65].base, - 16, g_bytes + 913), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 26), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[66].base, - 14, g_bytes + 929), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 27), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[67].base, - 16, g_bytes + 943), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 28), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[68].base, - 13, g_bytes + 959), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 29), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[14].base, - 12, g_bytes + 158), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 30), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[69].base, - 6, g_bytes + 972), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 31), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[70].base, - 4, g_bytes + 978), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 32), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[71].base, - 4, g_bytes + 982), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 33), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[72].base, - 6, g_bytes + 986), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 34), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[73].base, - 7, g_bytes + 992), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 35), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[74].base, - 4, g_bytes + 999), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 36), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[20].base, - 4, g_bytes + 278), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 37), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[75].base, - 8, g_bytes + 1003), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 38), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[76].base, - 17, g_bytes + 1011), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 39), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[77].base, - 13, g_bytes + 1028), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 40), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[78].base, - 8, g_bytes + 1041), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 41), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[79].base, - 19, g_bytes + 1049), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 42), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[80].base, - 13, g_bytes + 1068), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 43), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[81].base, - 4, g_bytes + 1081), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 44), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[82].base, - 8, g_bytes + 1085), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 45), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[83].base, - 12, g_bytes + 1093), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 46), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[84].base, - 18, g_bytes + 1105), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 47), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[85].base, - 19, g_bytes + 1123), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 48), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[86].base, - 5, g_bytes + 1142), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 49), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[87].base, - 7, g_bytes + 1147), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 50), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[88].base, - 7, g_bytes + 1154), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 51), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[89].base, - 11, g_bytes + 1161), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 52), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[90].base, - 6, g_bytes + 1172), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 53), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[91].base, - 10, g_bytes + 1178), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 54), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[92].base, - 25, g_bytes + 1188), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 55), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[93].base, - 17, g_bytes + 1213), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 56), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[19].base, - 10, g_bytes + 268), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 57), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[94].base, - 4, g_bytes + 1230), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 58), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[95].base, - 3, g_bytes + 1234), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 59), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[96].base, - 16, g_bytes + 1237), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 60), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[7].base, - 11, g_bytes + 50), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[97].base, - 1, g_bytes + 1253), - 61), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[7].base, - 11, g_bytes + 50), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[24].base, - 1, g_bytes + 342), - 62), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[7].base, - 11, g_bytes + 50), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[25].base, - 1, g_bytes + 343), - 63), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[9].base, - 13, g_bytes + 77), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[98].base, - 8, g_bytes + 1254), - 64), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[9].base, - 13, g_bytes + 77), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[39].base, - 4, g_bytes + 708), - 65), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[9].base, - 13, g_bytes + 77), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[38].base, - 7, g_bytes + 701), - 66), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[5].base, - 2, g_bytes + 36), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[99].base, - 8, g_bytes + 1262), - 67), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[14].base, - 12, g_bytes + 158), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[100].base, 16, g_bytes + 1270), - 68), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[4].base, - 7, g_bytes + 29), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[101].base, 4, g_bytes + 1286), - 69), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[1].base, - 7, g_bytes + 5), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[102].base, 3, g_bytes + 1290), - 70), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 71), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[15].base, - 16, g_bytes + 170), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[98].base, - 8, g_bytes + 1254), - 72), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[15].base, - 16, g_bytes + 170), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[39].base, - 4, g_bytes + 708), - 73), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[103].base, 11, g_bytes + 1293), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[28].base, - 0, g_bytes + 346), - 74), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[98].base, - 8, g_bytes + 1254), - 75), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[38].base, - 7, g_bytes + 701), - 76), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[104].base, 16, g_bytes + 1304), - 77), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[39].base, - 4, g_bytes + 708), - 78), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[105].base, 13, g_bytes + 1320), - 79), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[106].base, 12, g_bytes + 1333), - 80), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[10].base, - 20, g_bytes + 90), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[107].base, 21, g_bytes + 1345), - 81), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[98].base, - 8, g_bytes + 1254), - 82), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[39].base, - 4, g_bytes + 708), - 83), - grpc_core::StaticMetadata( - grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[16].base, - 15, g_bytes + 186), - grpc_core::StaticMetadataSlice( - &grpc_static_metadata_refcounts[105].base, 13, g_bytes + 1320), - 84), -}; const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 75, 76, 77, 78, 79, 80, 81}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 7ea000e1066..c465a2f37b7 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -37,240 +37,262 @@ static_assert( std::is_trivially_destructible::value, "grpc_core::StaticMetadataSlice must be trivially destructible."); #define GRPC_STATIC_MDSTR_COUNT 108 -extern const grpc_core::StaticMetadataSlice - grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; + +void grpc_init_static_metadata_ctx(void); +void grpc_destroy_static_metadata_ctx(void); +namespace grpc_core { +#ifndef NDEBUG +constexpr uint64_t kGrpcStaticMetadataInitCanary = 0xCAFEF00DC0FFEE11L; +uint64_t StaticMetadataInitCanary(); +#endif +extern const StaticMetadataSlice* g_static_metadata_slice_table; +} +inline const grpc_core::StaticMetadataSlice* grpc_static_slice_table() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() == + grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_metadata_slice_table != nullptr); + return grpc_core::g_static_metadata_slice_table; +} + /* ":path" */ -#define GRPC_MDSTR_PATH (grpc_static_slice_table[0]) +#define GRPC_MDSTR_PATH (grpc_static_slice_table()[0]) /* ":method" */ -#define GRPC_MDSTR_METHOD (grpc_static_slice_table[1]) +#define GRPC_MDSTR_METHOD (grpc_static_slice_table()[1]) /* ":status" */ -#define GRPC_MDSTR_STATUS (grpc_static_slice_table[2]) +#define GRPC_MDSTR_STATUS (grpc_static_slice_table()[2]) /* ":authority" */ -#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table[3]) +#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table()[3]) /* ":scheme" */ -#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[4]) +#define GRPC_MDSTR_SCHEME (grpc_static_slice_table()[4]) /* "te" */ -#define GRPC_MDSTR_TE (grpc_static_slice_table[5]) +#define GRPC_MDSTR_TE (grpc_static_slice_table()[5]) /* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[6]) +#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table()[6]) /* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[7]) +#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table()[7]) /* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[8]) +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table()[8]) /* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[9]) +#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table()[9]) /* "grpc-accept-encoding" */ -#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[10]) +#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table()[10]) /* "grpc-server-stats-bin" */ -#define GRPC_MDSTR_GRPC_SERVER_STATS_BIN (grpc_static_slice_table[11]) +#define GRPC_MDSTR_GRPC_SERVER_STATS_BIN (grpc_static_slice_table()[11]) /* "grpc-tags-bin" */ -#define GRPC_MDSTR_GRPC_TAGS_BIN (grpc_static_slice_table[12]) +#define GRPC_MDSTR_GRPC_TAGS_BIN (grpc_static_slice_table()[12]) /* "grpc-trace-bin" */ -#define GRPC_MDSTR_GRPC_TRACE_BIN (grpc_static_slice_table[13]) +#define GRPC_MDSTR_GRPC_TRACE_BIN (grpc_static_slice_table()[13]) /* "content-type" */ -#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table[14]) +#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table()[14]) /* "content-encoding" */ -#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table[15]) +#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table()[15]) /* "accept-encoding" */ -#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table[16]) +#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table()[16]) /* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[17]) +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST \ + (grpc_static_slice_table()[17]) /* "grpc-internal-stream-encoding-request" */ #define GRPC_MDSTR_GRPC_INTERNAL_STREAM_ENCODING_REQUEST \ - (grpc_static_slice_table[18]) + (grpc_static_slice_table()[18]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[19]) +#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table()[19]) /* "host" */ -#define GRPC_MDSTR_HOST (grpc_static_slice_table[20]) +#define GRPC_MDSTR_HOST (grpc_static_slice_table()[20]) /* "grpc-previous-rpc-attempts" */ -#define GRPC_MDSTR_GRPC_PREVIOUS_RPC_ATTEMPTS (grpc_static_slice_table[21]) +#define GRPC_MDSTR_GRPC_PREVIOUS_RPC_ATTEMPTS (grpc_static_slice_table()[21]) /* "grpc-retry-pushback-ms" */ -#define GRPC_MDSTR_GRPC_RETRY_PUSHBACK_MS (grpc_static_slice_table[22]) +#define GRPC_MDSTR_GRPC_RETRY_PUSHBACK_MS (grpc_static_slice_table()[22]) /* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[23]) +#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table()[23]) /* "1" */ -#define GRPC_MDSTR_1 (grpc_static_slice_table[24]) +#define GRPC_MDSTR_1 (grpc_static_slice_table()[24]) /* "2" */ -#define GRPC_MDSTR_2 (grpc_static_slice_table[25]) +#define GRPC_MDSTR_2 (grpc_static_slice_table()[25]) /* "3" */ -#define GRPC_MDSTR_3 (grpc_static_slice_table[26]) +#define GRPC_MDSTR_3 (grpc_static_slice_table()[26]) /* "4" */ -#define GRPC_MDSTR_4 (grpc_static_slice_table[27]) +#define GRPC_MDSTR_4 (grpc_static_slice_table()[27]) /* "" */ -#define GRPC_MDSTR_EMPTY (grpc_static_slice_table[28]) +#define GRPC_MDSTR_EMPTY (grpc_static_slice_table()[28]) /* "grpc.wait_for_ready" */ -#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table[29]) +#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table()[29]) /* "grpc.timeout" */ -#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table[30]) +#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table()[30]) /* "grpc.max_request_message_bytes" */ #define GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES \ - (grpc_static_slice_table[31]) + (grpc_static_slice_table()[31]) /* "grpc.max_response_message_bytes" */ #define GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES \ - (grpc_static_slice_table[32]) + (grpc_static_slice_table()[32]) /* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ #define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ - (grpc_static_slice_table[33]) + (grpc_static_slice_table()[33]) /* "/envoy.service.load_stats.v2.LoadReportingService/StreamLoadStats" */ #define GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_LOAD_STATS_DOT_V2_DOT_LOADREPORTINGSERVICE_SLASH_STREAMLOADSTATS \ - (grpc_static_slice_table[34]) + (grpc_static_slice_table()[34]) /* "/envoy.api.v2.EndpointDiscoveryService/StreamEndpoints" */ #define GRPC_MDSTR_SLASH_ENVOY_DOT_API_DOT_V2_DOT_ENDPOINTDISCOVERYSERVICE_SLASH_STREAMENDPOINTS \ - (grpc_static_slice_table[35]) + (grpc_static_slice_table()[35]) /* "/grpc.health.v1.Health/Watch" */ #define GRPC_MDSTR_SLASH_GRPC_DOT_HEALTH_DOT_V1_DOT_HEALTH_SLASH_WATCH \ - (grpc_static_slice_table[36]) + (grpc_static_slice_table()[36]) /* "/envoy.service.discovery.v2.AggregatedDiscoveryService/StreamAggregatedResources" */ #define GRPC_MDSTR_SLASH_ENVOY_DOT_SERVICE_DOT_DISCOVERY_DOT_V2_DOT_AGGREGATEDDISCOVERYSERVICE_SLASH_STREAMAGGREGATEDRESOURCES \ - (grpc_static_slice_table[37]) + (grpc_static_slice_table()[37]) /* "deflate" */ -#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[38]) +#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table()[38]) /* "gzip" */ -#define GRPC_MDSTR_GZIP (grpc_static_slice_table[39]) +#define GRPC_MDSTR_GZIP (grpc_static_slice_table()[39]) /* "stream/gzip" */ -#define GRPC_MDSTR_STREAM_SLASH_GZIP (grpc_static_slice_table[40]) +#define GRPC_MDSTR_STREAM_SLASH_GZIP (grpc_static_slice_table()[40]) /* "GET" */ -#define GRPC_MDSTR_GET (grpc_static_slice_table[41]) +#define GRPC_MDSTR_GET (grpc_static_slice_table()[41]) /* "POST" */ -#define GRPC_MDSTR_POST (grpc_static_slice_table[42]) +#define GRPC_MDSTR_POST (grpc_static_slice_table()[42]) /* "/" */ -#define GRPC_MDSTR_SLASH (grpc_static_slice_table[43]) +#define GRPC_MDSTR_SLASH (grpc_static_slice_table()[43]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[44]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table()[44]) /* "http" */ -#define GRPC_MDSTR_HTTP (grpc_static_slice_table[45]) +#define GRPC_MDSTR_HTTP (grpc_static_slice_table()[45]) /* "https" */ -#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[46]) +#define GRPC_MDSTR_HTTPS (grpc_static_slice_table()[46]) /* "200" */ -#define GRPC_MDSTR_200 (grpc_static_slice_table[47]) +#define GRPC_MDSTR_200 (grpc_static_slice_table()[47]) /* "204" */ -#define GRPC_MDSTR_204 (grpc_static_slice_table[48]) +#define GRPC_MDSTR_204 (grpc_static_slice_table()[48]) /* "206" */ -#define GRPC_MDSTR_206 (grpc_static_slice_table[49]) +#define GRPC_MDSTR_206 (grpc_static_slice_table()[49]) /* "304" */ -#define GRPC_MDSTR_304 (grpc_static_slice_table[50]) +#define GRPC_MDSTR_304 (grpc_static_slice_table()[50]) /* "400" */ -#define GRPC_MDSTR_400 (grpc_static_slice_table[51]) +#define GRPC_MDSTR_400 (grpc_static_slice_table()[51]) /* "404" */ -#define GRPC_MDSTR_404 (grpc_static_slice_table[52]) +#define GRPC_MDSTR_404 (grpc_static_slice_table()[52]) /* "500" */ -#define GRPC_MDSTR_500 (grpc_static_slice_table[53]) +#define GRPC_MDSTR_500 (grpc_static_slice_table()[53]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[54]) +#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table()[54]) /* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[55]) +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table()[55]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[56]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table()[56]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[57]) +#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table()[57]) /* "accept" */ -#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[58]) +#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table()[58]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[59]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table()[59]) /* "age" */ -#define GRPC_MDSTR_AGE (grpc_static_slice_table[60]) +#define GRPC_MDSTR_AGE (grpc_static_slice_table()[60]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[61]) +#define GRPC_MDSTR_ALLOW (grpc_static_slice_table()[61]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[62]) +#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table()[62]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[63]) +#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table()[63]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[64]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table()[64]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[65]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table()[65]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[66]) +#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table()[66]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[67]) +#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table()[67]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[68]) +#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table()[68]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[69]) +#define GRPC_MDSTR_COOKIE (grpc_static_slice_table()[69]) /* "date" */ -#define GRPC_MDSTR_DATE (grpc_static_slice_table[70]) +#define GRPC_MDSTR_DATE (grpc_static_slice_table()[70]) /* "etag" */ -#define GRPC_MDSTR_ETAG (grpc_static_slice_table[71]) +#define GRPC_MDSTR_ETAG (grpc_static_slice_table()[71]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[72]) +#define GRPC_MDSTR_EXPECT (grpc_static_slice_table()[72]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[73]) +#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table()[73]) /* "from" */ -#define GRPC_MDSTR_FROM (grpc_static_slice_table[74]) +#define GRPC_MDSTR_FROM (grpc_static_slice_table()[74]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[75]) +#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table()[75]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[76]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table()[76]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[77]) +#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table()[77]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[78]) +#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table()[78]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[79]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table()[79]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[80]) +#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table()[80]) /* "link" */ -#define GRPC_MDSTR_LINK (grpc_static_slice_table[81]) +#define GRPC_MDSTR_LINK (grpc_static_slice_table()[81]) /* "location" */ -#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[82]) +#define GRPC_MDSTR_LOCATION (grpc_static_slice_table()[82]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[83]) +#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table()[83]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[84]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table()[84]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[85]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table()[85]) /* "range" */ -#define GRPC_MDSTR_RANGE (grpc_static_slice_table[86]) +#define GRPC_MDSTR_RANGE (grpc_static_slice_table()[86]) /* "referer" */ -#define GRPC_MDSTR_REFERER (grpc_static_slice_table[87]) +#define GRPC_MDSTR_REFERER (grpc_static_slice_table()[87]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[88]) +#define GRPC_MDSTR_REFRESH (grpc_static_slice_table()[88]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[89]) +#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table()[89]) /* "server" */ -#define GRPC_MDSTR_SERVER (grpc_static_slice_table[90]) +#define GRPC_MDSTR_SERVER (grpc_static_slice_table()[90]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[91]) +#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table()[91]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[92]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table()[92]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[93]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table()[93]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[94]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table()[94]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[95]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table()[95]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[96]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table()[96]) /* "0" */ -#define GRPC_MDSTR_0 (grpc_static_slice_table[97]) +#define GRPC_MDSTR_0 (grpc_static_slice_table()[97]) /* "identity" */ -#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[98]) +#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table()[98]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[99]) +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table()[99]) /* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[100]) +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table()[100]) /* "grpc" */ -#define GRPC_MDSTR_GRPC (grpc_static_slice_table[101]) +#define GRPC_MDSTR_GRPC (grpc_static_slice_table()[101]) /* "PUT" */ -#define GRPC_MDSTR_PUT (grpc_static_slice_table[102]) +#define GRPC_MDSTR_PUT (grpc_static_slice_table()[102]) /* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[103]) +#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table()[103]) /* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[104]) +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table()[104]) /* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[105]) +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table()[105]) /* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[106]) +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table()[106]) /* "identity,deflate,gzip" */ #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_slice_table[107]) + (grpc_static_slice_table()[107]) namespace grpc_core { struct StaticSliceRefcount; +extern StaticSliceRefcount* g_static_metadata_slice_refcounts; +} // namespace grpc_core +inline grpc_core::StaticSliceRefcount* grpc_static_metadata_refcounts() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() == + grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_metadata_slice_refcounts != nullptr); + return grpc_core::g_static_metadata_slice_refcounts; } -extern grpc_core::StaticSliceRefcount - grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT]; + #define GRPC_IS_STATIC_METADATA_STRING(slice) \ ((slice).refcount != NULL && \ (slice).refcount->GetType() == grpc_slice_refcount::Type::STATIC) @@ -280,196 +302,216 @@ extern grpc_core::StaticSliceRefcount ->index) #define GRPC_STATIC_MDELEM_COUNT 85 -extern grpc_core::StaticMetadata - grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; + +namespace grpc_core { +extern StaticMetadata* g_static_mdelem_table; +extern grpc_mdelem* g_static_mdelem_manifested; +} // namespace grpc_core +inline grpc_core::StaticMetadata* grpc_static_mdelem_table() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() == + grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_mdelem_table != nullptr); + return grpc_core::g_static_mdelem_table; +} +inline grpc_mdelem* grpc_static_mdelem_manifested() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() == + grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_mdelem_manifested != nullptr); + return grpc_core::g_static_mdelem_manifested; +} + extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; -extern grpc_mdelem grpc_static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT]; /* ":authority": "" */ -#define GRPC_MDELEM_AUTHORITY_EMPTY (grpc_static_mdelem_manifested[0]) +#define GRPC_MDELEM_AUTHORITY_EMPTY (grpc_static_mdelem_manifested()[0]) /* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET (grpc_static_mdelem_manifested[1]) +#define GRPC_MDELEM_METHOD_GET (grpc_static_mdelem_manifested()[1]) /* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST (grpc_static_mdelem_manifested[2]) +#define GRPC_MDELEM_METHOD_POST (grpc_static_mdelem_manifested()[2]) /* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH (grpc_static_mdelem_manifested[3]) +#define GRPC_MDELEM_PATH_SLASH (grpc_static_mdelem_manifested()[3]) /* ":path": "/index.html" */ -#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (grpc_static_mdelem_manifested[4]) +#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ + (grpc_static_mdelem_manifested()[4]) /* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP (grpc_static_mdelem_manifested[5]) +#define GRPC_MDELEM_SCHEME_HTTP (grpc_static_mdelem_manifested()[5]) /* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS (grpc_static_mdelem_manifested[6]) +#define GRPC_MDELEM_SCHEME_HTTPS (grpc_static_mdelem_manifested()[6]) /* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 (grpc_static_mdelem_manifested[7]) +#define GRPC_MDELEM_STATUS_200 (grpc_static_mdelem_manifested()[7]) /* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 (grpc_static_mdelem_manifested[8]) +#define GRPC_MDELEM_STATUS_204 (grpc_static_mdelem_manifested()[8]) /* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 (grpc_static_mdelem_manifested[9]) +#define GRPC_MDELEM_STATUS_206 (grpc_static_mdelem_manifested()[9]) /* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 (grpc_static_mdelem_manifested[10]) +#define GRPC_MDELEM_STATUS_304 (grpc_static_mdelem_manifested()[10]) /* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 (grpc_static_mdelem_manifested[11]) +#define GRPC_MDELEM_STATUS_400 (grpc_static_mdelem_manifested()[11]) /* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 (grpc_static_mdelem_manifested[12]) +#define GRPC_MDELEM_STATUS_404 (grpc_static_mdelem_manifested()[12]) /* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 (grpc_static_mdelem_manifested[13]) +#define GRPC_MDELEM_STATUS_500 (grpc_static_mdelem_manifested()[13]) /* "accept-charset": "" */ -#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY (grpc_static_mdelem_manifested[14]) +#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY (grpc_static_mdelem_manifested()[14]) /* "accept-encoding": "gzip, deflate" */ #define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ - (grpc_static_mdelem_manifested[15]) + (grpc_static_mdelem_manifested()[15]) /* "accept-language": "" */ -#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY (grpc_static_mdelem_manifested[16]) +#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY (grpc_static_mdelem_manifested()[16]) /* "accept-ranges": "" */ -#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY (grpc_static_mdelem_manifested[17]) +#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY (grpc_static_mdelem_manifested()[17]) /* "accept": "" */ -#define GRPC_MDELEM_ACCEPT_EMPTY (grpc_static_mdelem_manifested[18]) +#define GRPC_MDELEM_ACCEPT_EMPTY (grpc_static_mdelem_manifested()[18]) /* "access-control-allow-origin": "" */ #define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ - (grpc_static_mdelem_manifested[19]) + (grpc_static_mdelem_manifested()[19]) /* "age": "" */ -#define GRPC_MDELEM_AGE_EMPTY (grpc_static_mdelem_manifested[20]) +#define GRPC_MDELEM_AGE_EMPTY (grpc_static_mdelem_manifested()[20]) /* "allow": "" */ -#define GRPC_MDELEM_ALLOW_EMPTY (grpc_static_mdelem_manifested[21]) +#define GRPC_MDELEM_ALLOW_EMPTY (grpc_static_mdelem_manifested()[21]) /* "authorization": "" */ -#define GRPC_MDELEM_AUTHORIZATION_EMPTY (grpc_static_mdelem_manifested[22]) +#define GRPC_MDELEM_AUTHORIZATION_EMPTY (grpc_static_mdelem_manifested()[22]) /* "cache-control": "" */ -#define GRPC_MDELEM_CACHE_CONTROL_EMPTY (grpc_static_mdelem_manifested[23]) +#define GRPC_MDELEM_CACHE_CONTROL_EMPTY (grpc_static_mdelem_manifested()[23]) /* "content-disposition": "" */ #define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY \ - (grpc_static_mdelem_manifested[24]) + (grpc_static_mdelem_manifested()[24]) /* "content-encoding": "" */ -#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY (grpc_static_mdelem_manifested[25]) +#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY (grpc_static_mdelem_manifested()[25]) /* "content-language": "" */ -#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY (grpc_static_mdelem_manifested[26]) +#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY (grpc_static_mdelem_manifested()[26]) /* "content-length": "" */ -#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY (grpc_static_mdelem_manifested[27]) +#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY (grpc_static_mdelem_manifested()[27]) /* "content-location": "" */ -#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY (grpc_static_mdelem_manifested[28]) +#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY (grpc_static_mdelem_manifested()[28]) /* "content-range": "" */ -#define GRPC_MDELEM_CONTENT_RANGE_EMPTY (grpc_static_mdelem_manifested[29]) +#define GRPC_MDELEM_CONTENT_RANGE_EMPTY (grpc_static_mdelem_manifested()[29]) /* "content-type": "" */ -#define GRPC_MDELEM_CONTENT_TYPE_EMPTY (grpc_static_mdelem_manifested[30]) +#define GRPC_MDELEM_CONTENT_TYPE_EMPTY (grpc_static_mdelem_manifested()[30]) /* "cookie": "" */ -#define GRPC_MDELEM_COOKIE_EMPTY (grpc_static_mdelem_manifested[31]) +#define GRPC_MDELEM_COOKIE_EMPTY (grpc_static_mdelem_manifested()[31]) /* "date": "" */ -#define GRPC_MDELEM_DATE_EMPTY (grpc_static_mdelem_manifested[32]) +#define GRPC_MDELEM_DATE_EMPTY (grpc_static_mdelem_manifested()[32]) /* "etag": "" */ -#define GRPC_MDELEM_ETAG_EMPTY (grpc_static_mdelem_manifested[33]) +#define GRPC_MDELEM_ETAG_EMPTY (grpc_static_mdelem_manifested()[33]) /* "expect": "" */ -#define GRPC_MDELEM_EXPECT_EMPTY (grpc_static_mdelem_manifested[34]) +#define GRPC_MDELEM_EXPECT_EMPTY (grpc_static_mdelem_manifested()[34]) /* "expires": "" */ -#define GRPC_MDELEM_EXPIRES_EMPTY (grpc_static_mdelem_manifested[35]) +#define GRPC_MDELEM_EXPIRES_EMPTY (grpc_static_mdelem_manifested()[35]) /* "from": "" */ -#define GRPC_MDELEM_FROM_EMPTY (grpc_static_mdelem_manifested[36]) +#define GRPC_MDELEM_FROM_EMPTY (grpc_static_mdelem_manifested()[36]) /* "host": "" */ -#define GRPC_MDELEM_HOST_EMPTY (grpc_static_mdelem_manifested[37]) +#define GRPC_MDELEM_HOST_EMPTY (grpc_static_mdelem_manifested()[37]) /* "if-match": "" */ -#define GRPC_MDELEM_IF_MATCH_EMPTY (grpc_static_mdelem_manifested[38]) +#define GRPC_MDELEM_IF_MATCH_EMPTY (grpc_static_mdelem_manifested()[38]) /* "if-modified-since": "" */ -#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY (grpc_static_mdelem_manifested[39]) +#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY \ + (grpc_static_mdelem_manifested()[39]) /* "if-none-match": "" */ -#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY (grpc_static_mdelem_manifested[40]) +#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY (grpc_static_mdelem_manifested()[40]) /* "if-range": "" */ -#define GRPC_MDELEM_IF_RANGE_EMPTY (grpc_static_mdelem_manifested[41]) +#define GRPC_MDELEM_IF_RANGE_EMPTY (grpc_static_mdelem_manifested()[41]) /* "if-unmodified-since": "" */ #define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY \ - (grpc_static_mdelem_manifested[42]) + (grpc_static_mdelem_manifested()[42]) /* "last-modified": "" */ -#define GRPC_MDELEM_LAST_MODIFIED_EMPTY (grpc_static_mdelem_manifested[43]) +#define GRPC_MDELEM_LAST_MODIFIED_EMPTY (grpc_static_mdelem_manifested()[43]) /* "link": "" */ -#define GRPC_MDELEM_LINK_EMPTY (grpc_static_mdelem_manifested[44]) +#define GRPC_MDELEM_LINK_EMPTY (grpc_static_mdelem_manifested()[44]) /* "location": "" */ -#define GRPC_MDELEM_LOCATION_EMPTY (grpc_static_mdelem_manifested[45]) +#define GRPC_MDELEM_LOCATION_EMPTY (grpc_static_mdelem_manifested()[45]) /* "max-forwards": "" */ -#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (grpc_static_mdelem_manifested[46]) +#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (grpc_static_mdelem_manifested()[46]) /* "proxy-authenticate": "" */ -#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (grpc_static_mdelem_manifested[47]) +#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY \ + (grpc_static_mdelem_manifested()[47]) /* "proxy-authorization": "" */ #define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY \ - (grpc_static_mdelem_manifested[48]) + (grpc_static_mdelem_manifested()[48]) /* "range": "" */ -#define GRPC_MDELEM_RANGE_EMPTY (grpc_static_mdelem_manifested[49]) +#define GRPC_MDELEM_RANGE_EMPTY (grpc_static_mdelem_manifested()[49]) /* "referer": "" */ -#define GRPC_MDELEM_REFERER_EMPTY (grpc_static_mdelem_manifested[50]) +#define GRPC_MDELEM_REFERER_EMPTY (grpc_static_mdelem_manifested()[50]) /* "refresh": "" */ -#define GRPC_MDELEM_REFRESH_EMPTY (grpc_static_mdelem_manifested[51]) +#define GRPC_MDELEM_REFRESH_EMPTY (grpc_static_mdelem_manifested()[51]) /* "retry-after": "" */ -#define GRPC_MDELEM_RETRY_AFTER_EMPTY (grpc_static_mdelem_manifested[52]) +#define GRPC_MDELEM_RETRY_AFTER_EMPTY (grpc_static_mdelem_manifested()[52]) /* "server": "" */ -#define GRPC_MDELEM_SERVER_EMPTY (grpc_static_mdelem_manifested[53]) +#define GRPC_MDELEM_SERVER_EMPTY (grpc_static_mdelem_manifested()[53]) /* "set-cookie": "" */ -#define GRPC_MDELEM_SET_COOKIE_EMPTY (grpc_static_mdelem_manifested[54]) +#define GRPC_MDELEM_SET_COOKIE_EMPTY (grpc_static_mdelem_manifested()[54]) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - (grpc_static_mdelem_manifested[55]) + (grpc_static_mdelem_manifested()[55]) /* "transfer-encoding": "" */ -#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (grpc_static_mdelem_manifested[56]) +#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY \ + (grpc_static_mdelem_manifested()[56]) /* "user-agent": "" */ -#define GRPC_MDELEM_USER_AGENT_EMPTY (grpc_static_mdelem_manifested[57]) +#define GRPC_MDELEM_USER_AGENT_EMPTY (grpc_static_mdelem_manifested()[57]) /* "vary": "" */ -#define GRPC_MDELEM_VARY_EMPTY (grpc_static_mdelem_manifested[58]) +#define GRPC_MDELEM_VARY_EMPTY (grpc_static_mdelem_manifested()[58]) /* "via": "" */ -#define GRPC_MDELEM_VIA_EMPTY (grpc_static_mdelem_manifested[59]) +#define GRPC_MDELEM_VIA_EMPTY (grpc_static_mdelem_manifested()[59]) /* "www-authenticate": "" */ -#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (grpc_static_mdelem_manifested[60]) +#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (grpc_static_mdelem_manifested()[60]) /* "grpc-status": "0" */ -#define GRPC_MDELEM_GRPC_STATUS_0 (grpc_static_mdelem_manifested[61]) +#define GRPC_MDELEM_GRPC_STATUS_0 (grpc_static_mdelem_manifested()[61]) /* "grpc-status": "1" */ -#define GRPC_MDELEM_GRPC_STATUS_1 (grpc_static_mdelem_manifested[62]) +#define GRPC_MDELEM_GRPC_STATUS_1 (grpc_static_mdelem_manifested()[62]) /* "grpc-status": "2" */ -#define GRPC_MDELEM_GRPC_STATUS_2 (grpc_static_mdelem_manifested[63]) +#define GRPC_MDELEM_GRPC_STATUS_2 (grpc_static_mdelem_manifested()[63]) /* "grpc-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY (grpc_static_mdelem_manifested[64]) +#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY (grpc_static_mdelem_manifested()[64]) /* "grpc-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ENCODING_GZIP (grpc_static_mdelem_manifested[65]) +#define GRPC_MDELEM_GRPC_ENCODING_GZIP (grpc_static_mdelem_manifested()[65]) /* "grpc-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE (grpc_static_mdelem_manifested[66]) +#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE (grpc_static_mdelem_manifested()[66]) /* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS (grpc_static_mdelem_manifested[67]) +#define GRPC_MDELEM_TE_TRAILERS (grpc_static_mdelem_manifested()[67]) /* "content-type": "application/grpc" */ #define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ - (grpc_static_mdelem_manifested[68]) + (grpc_static_mdelem_manifested()[68]) /* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC (grpc_static_mdelem_manifested[69]) +#define GRPC_MDELEM_SCHEME_GRPC (grpc_static_mdelem_manifested()[69]) /* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT (grpc_static_mdelem_manifested[70]) +#define GRPC_MDELEM_METHOD_PUT (grpc_static_mdelem_manifested()[70]) /* "accept-encoding": "" */ -#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY (grpc_static_mdelem_manifested[71]) +#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY (grpc_static_mdelem_manifested()[71]) /* "content-encoding": "identity" */ #define GRPC_MDELEM_CONTENT_ENCODING_IDENTITY \ - (grpc_static_mdelem_manifested[72]) + (grpc_static_mdelem_manifested()[72]) /* "content-encoding": "gzip" */ -#define GRPC_MDELEM_CONTENT_ENCODING_GZIP (grpc_static_mdelem_manifested[73]) +#define GRPC_MDELEM_CONTENT_ENCODING_GZIP (grpc_static_mdelem_manifested()[73]) /* "lb-cost-bin": "" */ -#define GRPC_MDELEM_LB_COST_BIN_EMPTY (grpc_static_mdelem_manifested[74]) +#define GRPC_MDELEM_LB_COST_BIN_EMPTY (grpc_static_mdelem_manifested()[74]) /* "grpc-accept-encoding": "identity" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ - (grpc_static_mdelem_manifested[75]) + (grpc_static_mdelem_manifested()[75]) /* "grpc-accept-encoding": "deflate" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ - (grpc_static_mdelem_manifested[76]) + (grpc_static_mdelem_manifested()[76]) /* "grpc-accept-encoding": "identity,deflate" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ - (grpc_static_mdelem_manifested[77]) + (grpc_static_mdelem_manifested()[77]) /* "grpc-accept-encoding": "gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ - (grpc_static_mdelem_manifested[78]) + (grpc_static_mdelem_manifested()[78]) /* "grpc-accept-encoding": "identity,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - (grpc_static_mdelem_manifested[79]) + (grpc_static_mdelem_manifested()[79]) /* "grpc-accept-encoding": "deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ - (grpc_static_mdelem_manifested[80]) + (grpc_static_mdelem_manifested()[80]) /* "grpc-accept-encoding": "identity,deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_mdelem_manifested[81]) + (grpc_static_mdelem_manifested()[81]) /* "accept-encoding": "identity" */ -#define GRPC_MDELEM_ACCEPT_ENCODING_IDENTITY (grpc_static_mdelem_manifested[82]) +#define GRPC_MDELEM_ACCEPT_ENCODING_IDENTITY \ + (grpc_static_mdelem_manifested()[82]) /* "accept-encoding": "gzip" */ -#define GRPC_MDELEM_ACCEPT_ENCODING_GZIP (grpc_static_mdelem_manifested[83]) +#define GRPC_MDELEM_ACCEPT_ENCODING_GZIP (grpc_static_mdelem_manifested()[83]) /* "accept-encoding": "identity,gzip" */ #define GRPC_MDELEM_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - (grpc_static_mdelem_manifested[84]) + (grpc_static_mdelem_manifested()[84]) grpc_mdelem grpc_static_mdelem_for_static_strings(intptr_t a, intptr_t b); typedef enum { @@ -539,15 +581,15 @@ typedef union { : GRPC_BATCH_CALLOUTS_COUNT) extern const uint8_t grpc_static_accept_encoding_metadata[8]; -#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ - (GRPC_MAKE_MDELEM( \ - &grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]] \ - .data(), \ - GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table() \ + [grpc_static_accept_encoding_metadata[(algs)]] \ + .data(), \ + GRPC_MDELEM_STORAGE_STATIC)) extern const uint8_t grpc_static_accept_stream_encoding_metadata[4]; #define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table() \ [grpc_static_accept_stream_encoding_metadata[(algs)]] \ .data(), \ GRPC_MDELEM_STORAGE_STATIC)) diff --git a/test/core/slice/slice_test.cc b/test/core/slice/slice_test.cc index 4f824cbd5ad..fedda5f493f 100644 --- a/test/core/slice/slice_test.cc +++ b/test/core/slice/slice_test.cc @@ -265,8 +265,8 @@ static void test_static_slice_interning(void) { for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { GPR_ASSERT(grpc_slice_is_equivalent( - grpc_static_slice_table[i], - grpc_slice_intern(grpc_static_slice_table[i]))); + grpc_static_slice_table()[i], + grpc_slice_intern(grpc_static_slice_table()[i]))); } } @@ -276,9 +276,9 @@ static void test_static_slice_copy_interning(void) { grpc_init(); for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - grpc_slice copy = grpc_slice_dup(grpc_static_slice_table[i]); - GPR_ASSERT(grpc_static_slice_table[i].refcount != copy.refcount); - GPR_ASSERT(grpc_static_slice_table[i].refcount == + grpc_slice copy = grpc_slice_dup(grpc_static_slice_table()[i]); + GPR_ASSERT(grpc_static_slice_table()[i].refcount != copy.refcount); + GPR_ASSERT(grpc_static_slice_table()[i].refcount == grpc_slice_intern(copy).refcount); grpc_slice_unref(copy); } diff --git a/test/core/transport/metadata_test.cc b/test/core/transport/metadata_test.cc index e6b73de2de5..0786d78d7f9 100644 --- a/test/core/transport/metadata_test.cc +++ b/test/core/transport/metadata_test.cc @@ -373,7 +373,7 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { grpc_core::ExecCtx exec_ctx; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], + grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[i], GRPC_MDELEM_STORAGE_STATIC); grpc_mdelem q = grpc_mdelem_from_slices(maybe_dup(GRPC_MDKEY(p), dup_key), diff --git a/test/core/transport/status_metadata_test.cc b/test/core/transport/status_metadata_test.cc index a96f11c1ea3..d5723a4313f 100644 --- a/test/core/transport/status_metadata_test.cc +++ b/test/core/transport/status_metadata_test.cc @@ -57,5 +57,8 @@ TEST(GetStatusCodeFromMetadata, Unparseable) { int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index fc1bfe99934..d79759f541c 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -393,12 +393,24 @@ for i, elem in enumerate(all_strs): str_ofs += len(elem) +def slice_def_for_ctx(i): + return ( + 'grpc_core::StaticMetadataSlice(&refcounts[%d].base, %d, g_bytes+%d)' + ) % (i, len(all_strs[i]), id2strofs[i]) + + def slice_def(i): return ( - 'grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts[%d].base, %d, g_bytes+%d)' + 'grpc_core::StaticMetadataSlice(&grpc_static_metadata_refcounts()[%d].base, %d, g_bytes+%d)' ) % (i, len(all_strs[i]), id2strofs[i]) +def str_idx(s): + for i, s2 in enumerate(all_strs): + if s == s2: + return i + + # validate configuration for elem in METADATA_BATCH_CALLOUTS: assert elem in all_strs @@ -408,55 +420,70 @@ static_slice_dest_assert = ( '"grpc_core::StaticMetadataSlice must be trivially destructible.");') print >> H, static_slice_dest_assert print >> H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) -print >> H, ('extern const grpc_core::StaticMetadataSlice ' - 'grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];') +print >> H, ''' +void grpc_init_static_metadata_ctx(void); +void grpc_destroy_static_metadata_ctx(void); +namespace grpc_core { +#ifndef NDEBUG +constexpr uint64_t kGrpcStaticMetadataInitCanary = 0xCAFEF00DC0FFEE11L; +uint64_t StaticMetadataInitCanary(); +#endif +extern const StaticMetadataSlice* g_static_metadata_slice_table; +} +inline const grpc_core::StaticMetadataSlice* grpc_static_slice_table() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() + == grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_metadata_slice_table != nullptr); + return grpc_core::g_static_metadata_slice_table; +} +''' for i, elem in enumerate(all_strs): print >> H, '/* "%s" */' % elem - print >> H, '#define %s (grpc_static_slice_table[%d])' % ( + print >> H, '#define %s (grpc_static_slice_table()[%d])' % ( mangle(elem).upper(), i) print >> H -print >> C, 'static uint8_t g_bytes[] = {%s};' % (','.join( +print >> C, 'static constexpr uint8_t g_bytes[] = {%s};' % (','.join( '%d' % ord(c) for c in ''.join(all_strs))) print >> C -print >> H, ('namespace grpc_core { struct StaticSliceRefcount; }') -print >> H, ('extern grpc_core::StaticSliceRefcount ' - 'grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT];') +print >> H, ''' +namespace grpc_core { +struct StaticSliceRefcount; +extern StaticSliceRefcount* g_static_metadata_slice_refcounts; +} +inline grpc_core::StaticSliceRefcount* grpc_static_metadata_refcounts() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() + == grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_metadata_slice_refcounts != nullptr); + return grpc_core::g_static_metadata_slice_refcounts; +} +''' print >> C, 'grpc_slice_refcount grpc_core::StaticSliceRefcount::kStaticSubRefcount;' -print >> C, ('grpc_core::StaticSliceRefcount ' - 'grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = {') -for i, elem in enumerate(all_strs): - print >> C, ' grpc_core::StaticSliceRefcount(%d), ' % i -print >> C, '};' -print >> C -print >> H, '#define GRPC_IS_STATIC_METADATA_STRING(slice) \\' -print >> H, (' ((slice).refcount != NULL && (slice).refcount->GetType() == ' - 'grpc_slice_refcount::Type::STATIC)') -print >> H -print >> C, ( - 'const grpc_core::StaticMetadataSlice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]' - ' = {') +print >> C, ''' +namespace grpc_core { +struct StaticMetadataCtx { +#ifndef NDEBUG + const uint64_t init_canary = kGrpcStaticMetadataInitCanary; +#endif + StaticSliceRefcount + refcounts[GRPC_STATIC_MDSTR_COUNT] = { +''' for i, elem in enumerate(all_strs): - print >> C, slice_def(i) + ',' -print >> C, '};' + print >> C, ' StaticSliceRefcount(%d), ' % i +print >> C, '};' # static slice refcounts print >> C -print >> H, '#define GRPC_STATIC_METADATA_INDEX(static_slice) \\' -print >> H, '(reinterpret_cast((static_slice).refcount)->index)' -print >> H - -print >> D, '# hpack fuzzing dictionary' +print >> C, ''' + const StaticMetadataSlice + slices[GRPC_STATIC_MDSTR_COUNT] = { +''' for i, elem in enumerate(all_strs): - print >> D, '%s' % (esc_dict([len(elem)] + [ord(c) for c in elem])) -for i, elem in enumerate(all_elems): - print >> D, '%s' % (esc_dict([0, len(elem[0])] + [ord(c) for c in elem[0]] + - [len(elem[1])] + [ord(c) for c in elem[1]])) - -print >> H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) -print >> H, ('extern grpc_core::StaticMetadata ' - 'grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];') -print >> H, ('extern uintptr_t ' - 'grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];') -print >> H, ('extern grpc_mdelem ' - 'grpc_static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT];') + print >> C, slice_def_for_ctx(i) + ',' +print >> C, '};' # static slices +print >> C, 'StaticMetadata static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' +for idx, (a, b) in enumerate(all_elems): + print >> C, 'StaticMetadata(%s,%s, %d),' % (slice_def_for_ctx(str_idx(a)), + slice_def_for_ctx(str_idx(b)), + idx) +print >> C, '};' # static_mdelem_table print >> C, (''' /* Warning: the core static metadata currently operates under the soft constraint that the first GRPC_CHTTP2_LAST_STATIC_ENTRY (61) entries must contain @@ -466,7 +493,7 @@ metadata is to be changed, then the CHTTP2 transport must be changed as well to stop relying on the core metadata. */ ''') print >> C, ('grpc_mdelem ' - 'grpc_static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT] = {') + 'static_mdelem_manifested[GRPC_STATIC_MDELEM_COUNT] = {') print >> C, '// clang-format off' static_mds = [] for i, elem in enumerate(all_elems): @@ -474,18 +501,97 @@ for i, elem in enumerate(all_elems): md_human_readable = '"%s": "%s"' % elem md_spec = ' /* %s: \n %s */\n' % (md_name, md_human_readable) md_spec += ' GRPC_MAKE_MDELEM(\n' - md_spec += ((' &grpc_static_mdelem_table[%d].data(),\n' % i) + + md_spec += ((' &static_mdelem_table[%d].data(),\n' % i) + ' GRPC_MDELEM_STORAGE_STATIC)') static_mds.append(md_spec) print >> C, ',\n'.join(static_mds) print >> C, '// clang-format on' -print >> C, ('};') +print >> C, ('};') # static_mdelem_manifested +print >> C, '};' # struct StaticMetadataCtx +print >> C, '}' # namespace grpc_core +print >> C, ''' +namespace grpc_core { +static StaticMetadataCtx* g_static_metadata_slice_ctx = nullptr; +const StaticMetadataSlice* g_static_metadata_slice_table = nullptr; +StaticSliceRefcount* g_static_metadata_slice_refcounts = nullptr; +StaticMetadata* g_static_mdelem_table = nullptr; +grpc_mdelem* g_static_mdelem_manifested = nullptr; +#ifndef NDEBUG +uint64_t StaticMetadataInitCanary() { + return g_static_metadata_slice_ctx->init_canary; +} +#endif +} + +void grpc_init_static_metadata_ctx(void) { + grpc_core::g_static_metadata_slice_ctx + = grpc_core::New(); + grpc_core::g_static_metadata_slice_table + = grpc_core::g_static_metadata_slice_ctx->slices; + grpc_core::g_static_metadata_slice_refcounts + = grpc_core::g_static_metadata_slice_ctx->refcounts; + grpc_core::g_static_mdelem_table + = grpc_core::g_static_metadata_slice_ctx->static_mdelem_table; + grpc_core::g_static_mdelem_manifested = + grpc_core::g_static_metadata_slice_ctx->static_mdelem_manifested; +} + +void grpc_destroy_static_metadata_ctx(void) { + grpc_core::Delete( + grpc_core::g_static_metadata_slice_ctx); + grpc_core::g_static_metadata_slice_ctx = nullptr; + grpc_core::g_static_metadata_slice_table = nullptr; + grpc_core::g_static_metadata_slice_refcounts = nullptr; + grpc_core::g_static_mdelem_table = nullptr; + grpc_core::g_static_mdelem_manifested = nullptr; +} + +''' + +print >> C +print >> H, '#define GRPC_IS_STATIC_METADATA_STRING(slice) \\' +print >> H, (' ((slice).refcount != NULL && (slice).refcount->GetType() == ' + 'grpc_slice_refcount::Type::STATIC)') +print >> H +print >> C +print >> H, '#define GRPC_STATIC_METADATA_INDEX(static_slice) \\' +print >> H, '(reinterpret_cast((static_slice).refcount)->index)' +print >> H + +print >> D, '# hpack fuzzing dictionary' +for i, elem in enumerate(all_strs): + print >> D, '%s' % (esc_dict([len(elem)] + [ord(c) for c in elem])) +for i, elem in enumerate(all_elems): + print >> D, '%s' % (esc_dict([0, len(elem[0])] + [ord(c) for c in elem[0]] + + [len(elem[1])] + [ord(c) for c in elem[1]])) + +print >> H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) +print >> H, ''' +namespace grpc_core { +extern StaticMetadata* g_static_mdelem_table; +extern grpc_mdelem* g_static_mdelem_manifested; +} +inline grpc_core::StaticMetadata* grpc_static_mdelem_table() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() + == grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_mdelem_table != nullptr); + return grpc_core::g_static_mdelem_table; +} +inline grpc_mdelem* grpc_static_mdelem_manifested() { + GPR_DEBUG_ASSERT(grpc_core::StaticMetadataInitCanary() + == grpc_core::kGrpcStaticMetadataInitCanary); + GPR_DEBUG_ASSERT(grpc_core::g_static_mdelem_manifested != nullptr); + return grpc_core::g_static_mdelem_manifested; +} +''' +print >> H, ('extern uintptr_t ' + 'grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];') for i, elem in enumerate(all_elems): md_name = mangle(elem).upper() print >> H, '/* "%s": "%s" */' % elem - print >> H, ('#define %s (grpc_static_mdelem_manifested[%d])' % (md_name, - i)) + print >> H, ('#define %s (grpc_static_mdelem_manifested()[%d])' % (md_name, + i)) print >> H print >> C, ('uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] ' @@ -496,12 +602,6 @@ print >> C, '};' print >> C -def str_idx(s): - for i, s2 in enumerate(all_strs): - if s == s2: - return i - - def md_idx(m): for i, m2 in enumerate(all_elems): if m == m2: @@ -575,16 +675,10 @@ print >> C, 'grpc_mdelem grpc_static_mdelem_for_static_strings(intptr_t a, intpt print >> C, ' if (a == -1 || b == -1) return GRPC_MDNULL;' print >> C, ' uint32_t k = static_cast(a * %d + b);' % len(all_strs) print >> C, ' uint32_t h = elems_phash(k);' -print >> C, ' return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k && elem_idxs[h] != 255 ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]].data(), GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL;' +print >> C, ' return h < GPR_ARRAY_SIZE(elem_keys) && elem_keys[h] == k && elem_idxs[h] != 255 ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[elem_idxs[h]].data(), GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL;' print >> C, '}' print >> C -print >> C, 'grpc_core::StaticMetadata grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' -for idx, (a, b) in enumerate(all_elems): - print >> C, 'grpc_core::StaticMetadata(%s,%s, %d),' % ( - slice_def(str_idx(a)), slice_def(str_idx(b)), idx) -print >> C, '};' - print >> H, 'typedef enum {' for elem in METADATA_BATCH_CALLOUTS: print >> H, ' %s,' % mangle(elem, 'batch').upper() @@ -629,7 +723,7 @@ print >> C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) print >> C, '};' print >> C -print >> H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]].data(), GRPC_MDELEM_STORAGE_STATIC))' +print >> H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[grpc_static_accept_encoding_metadata[(algs)]].data(), GRPC_MDELEM_STORAGE_STATIC))' print >> H print >> H, 'extern const uint8_t grpc_static_accept_stream_encoding_metadata[%d];' % ( @@ -640,7 +734,7 @@ print >> C, '0,%s' % ','.join( '%d' % md_idx(elem) for elem in stream_compression_elems) print >> C, '};' -print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_stream_encoding_metadata[(algs)]].data(), GRPC_MDELEM_STORAGE_STATIC))' +print >> H, '#define GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table()[grpc_static_accept_stream_encoding_metadata[(algs)]].data(), GRPC_MDELEM_STORAGE_STATIC))' print >> H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' From 426450cd82b9cc0edc7983049791904e327d49e8 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Fri, 2 Aug 2019 11:04:28 -0700 Subject: [PATCH 42/57] Implement dual testing --- BUILD | 2 +- bazel/grpc_python_deps.bzl | 9 ++ bazel/python_rules.bzl | 26 ++++++ .../grpcio_tests/tests/unit/BUILD.bazel | 4 +- third_party/py/BUILD.tpl | 49 +++++----- third_party/py/python_configure.bzl | 92 +++++++++++-------- third_party/py/remote.BUILD.tpl | 10 -- third_party/py/variety.tpl | 26 ++++++ tools/bazel.rc | 4 - 9 files changed, 142 insertions(+), 80 deletions(-) delete mode 100644 third_party/py/remote.BUILD.tpl create mode 100644 third_party/py/variety.tpl diff --git a/BUILD b/BUILD index f2a6f67f69f..74e1849629d 100644 --- a/BUILD +++ b/BUILD @@ -65,7 +65,7 @@ config_setting( config_setting( name = "python3", - values = {"python_path": "python3"}, + flag_values = {"@bazel_tools//tools/python:python_version": "PY3"}, ) config_setting( diff --git a/bazel/grpc_python_deps.bzl b/bazel/grpc_python_deps.bzl index 4e7cc1537fa..2a439bdf226 100644 --- a/bazel/grpc_python_deps.bzl +++ b/bazel/grpc_python_deps.bzl @@ -47,6 +47,15 @@ def grpc_python_deps(): remote = "https://github.com/bazelbuild/rules_python.git", ) + + if "rules_python" not in native.existing_rules(): + http_archive( + name = "rules_python", + url = "https://github.com/bazelbuild/rules_python/archive/9d68f24659e8ce8b736590ba1e4418af06ec2552.zip", + sha256 = "f7402f11691d657161f871e11968a984e5b48b023321935f5a55d7e56cf4758a", + strip_prefix = "rules_python-9d68f24659e8ce8b736590ba1e4418af06ec2552", + ) + python_configure(name = "local_config_python") native.bind( diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 12f51f8b172..e7e9e597b05 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -178,3 +178,29 @@ def py_grpc_library( deps = [Label("//src/python/grpcio/grpc:grpcio")] + deps, **kwargs ) + + +def py2and3_test(name, + py_test = native.py_test, + **kwargs): + if "python_version" in kwargs: + fail("Cannot specify 'python_version' in py2and3_test.") + + names = [name + suffix for suffix in (".python2", ".python3")] + python_versions = ["PY2", "PY3"] + for case_name, python_version in zip(names, python_versions): + py_test( + name = case_name, + python_version = python_version, + **kwargs + ) + + suite_kwargs = {} + if "visibility" in kwargs: + suite_kwargs["visibility"] = kwargs["visibility"] + + native.test_suite( + name = name, + tests = names, + **suite_kwargs + ) diff --git a/src/python/grpcio_tests/tests/unit/BUILD.bazel b/src/python/grpcio_tests/tests/unit/BUILD.bazel index 49203b7fa16..587d8cb246f 100644 --- a/src/python/grpcio_tests/tests/unit/BUILD.bazel +++ b/src/python/grpcio_tests/tests/unit/BUILD.bazel @@ -1,3 +1,5 @@ +load("//bazel:python_rules.bzl", "py2and3_test") + package(default_visibility = ["//visibility:public"]) GRPCIO_TESTS_UNIT = [ @@ -80,7 +82,7 @@ py_library( ) [ - py_test( + py2and3_test( name=test_file_name[:-3], size="small", srcs=[test_file_name], diff --git a/third_party/py/BUILD.tpl b/third_party/py/BUILD.tpl index 2283c573bc3..8f010f85a03 100644 --- a/third_party/py/BUILD.tpl +++ b/third_party/py/BUILD.tpl @@ -2,35 +2,36 @@ package(default_visibility=["//visibility:public"]) -# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib -# See https://docs.python.org/3/extending/windows.html -cc_import( - name="python_lib", - interface_library=select({ - ":windows": ":python_import_lib", - # A placeholder for Unix platforms which makes --no_build happy. - "//conditions:default": "not-existing.lib", - }), - system_provided=1, -) - -cc_library( - name="python_headers", - hdrs=[":python_include"], - deps=select({ - ":windows": [":python_lib"], - "//conditions:default": [], - }), - includes=["python_include"], -) - config_setting( name="windows", values={"cpu": "x64_windows"}, visibility=["//visibility:public"], ) -%{PYTHON_INCLUDE_GENRULE} -%{PYTHON_IMPORT_LIB_GENRULE} +config_setting( + name="python2", + flag_values = {"@rules_python//python:python_version": "PY2"} +) + +config_setting( + name="python3", + flag_values = {"@rules_python//python:python_version": "PY3"} +) +cc_library( + name = "python_lib", + deps = select({ + ":python2": ["//_python2:_python2_lib"], + ":python3": ["//_python3:_python3_lib"], + "//conditions:default": ["not-existing.lib"], + }) +) +cc_library( + name = "python_headers", + deps = select({ + ":python2": ["//_python2:_python2_headers"], + ":python3": ["//_python3:_python3_headers"], + "//conditions:default": ["not-existing.headers"], + }) +) diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl index e6fa5ed10e9..a2f0c7918d2 100644 --- a/third_party/py/python_configure.bzl +++ b/third_party/py/python_configure.bzl @@ -3,14 +3,15 @@ `python_configure` depends on the following environment variables: - * `PYTHON_BIN_PATH`: location of python binary. - * `PYTHON_LIB_PATH`: Location of python libraries. + * `PYTHON2_BIN_PATH`: location of python binary. + * `PYTHON2_LIB_PATH`: Location of python libraries. """ _BAZEL_SH = "BAZEL_SH" -_PYTHON_BIN_PATH = "PYTHON_BIN_PATH" -_PYTHON_LIB_PATH = "PYTHON_LIB_PATH" -_PYTHON_CONFIG_REPO = "PYTHON_CONFIG_REPO" +_PYTHON2_BIN_PATH = "PYTHON2_BIN_PATH" +_PYTHON2_LIB_PATH = "PYTHON2_LIB_PATH" +_PYTHON3_BIN_PATH = "PYTHON3_BIN_PATH" +_PYTHON3_LIB_PATH = "PYTHON3_LIB_PATH" def _tpl(repository_ctx, tpl, substitutions={}, out=None): @@ -136,9 +137,9 @@ def _symlink_genrule_for_dir(repository_ctx, "\n".join(outs)) -def _get_python_bin(repository_ctx): +def _get_python_bin(repository_ctx, bin_path_key, default_bin_path): """Gets the python bin path.""" - python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH, 'python') + python_bin = repository_ctx.os.environ.get(bin_path_key, default_bin_path) if not repository_ctx.path(python_bin).exists: # It's a command, use 'which' to find its path. python_bin_path = repository_ctx.which(python_bin) @@ -150,7 +151,7 @@ def _get_python_bin(repository_ctx): _fail("Cannot find python in PATH, please make sure " + "python is installed and add its directory in PATH, or --define " + "%s='/something/else'.\nPATH=%s" % - (_PYTHON_BIN_PATH, repository_ctx.os.environ.get("PATH", ""))) + (bin_path_key, repository_ctx.os.environ.get("PATH", ""))) def _get_bash_bin(repository_ctx): @@ -170,9 +171,9 @@ def _get_bash_bin(repository_ctx): (_BAZEL_SH, repository_ctx.os.environ.get("PATH", ""))) -def _get_python_lib(repository_ctx, python_bin): +def _get_python_lib(repository_ctx, python_bin, lib_path_key): """Gets the python lib path.""" - python_lib = repository_ctx.os.environ.get(_PYTHON_LIB_PATH) + python_lib = repository_ctx.os.environ.get(lib_path_key) if python_lib != None: return python_lib print_lib = ( @@ -202,13 +203,13 @@ def _check_python_lib(repository_ctx, python_lib): _fail("Invalid python library path: %s" % python_lib) -def _check_python_bin(repository_ctx, python_bin): +def _check_python_bin(repository_ctx, python_bin, bin_path_key): """Checks the python bin path.""" cmd = '[[ -x "%s" ]] && [[ ! -d "%s" ]]' % (python_bin, python_bin) result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd]) if result.return_code == 1: _fail("--define %s='%s' is not executable. Is it the python binary?" % - (_PYTHON_BIN_PATH, python_bin)) + (bin_path_key, python_bin)) def _get_python_include(repository_ctx, python_bin): @@ -222,11 +223,11 @@ def _get_python_include(repository_ctx, python_bin): error_msg="Problem getting python include path.", error_details=( "Is the Python binary path set up right? " + "(See ./configure or " - + _PYTHON_BIN_PATH + ".) " + "Is distutils installed?")) + + _PYTHON2_BIN_PATH + ".) " + "Is distutils installed?")) return result.stdout.splitlines()[0] -def _get_python_import_lib_name(repository_ctx, python_bin): +def _get_python_import_lib_name(repository_ctx, python_bin, bin_path_key): """Get Python import library name (pythonXY.lib) on Windows.""" result = _execute( repository_ctx, [ @@ -236,66 +237,77 @@ def _get_python_import_lib_name(repository_ctx, python_bin): ], error_msg="Problem getting python import library.", error_details=("Is the Python binary path set up right? " + - "(See ./configure or " + _PYTHON_BIN_PATH + ".) ")) + "(See ./configure or " + bin_path_key + ".) ")) return result.stdout.splitlines()[0] -def _create_local_python_repository(repository_ctx): +# TODO(rbellevi): Rename. +def _create_local_python_repository(repository_ctx, + variety_name, + bin_path_key, + default_bin_path, + lib_path_key): """Creates the repository containing files set up to build with Python.""" - python_bin = _get_python_bin(repository_ctx) - _check_python_bin(repository_ctx, python_bin) - python_lib = _get_python_lib(repository_ctx, python_bin) + python_bin = _get_python_bin(repository_ctx, bin_path_key, default_bin_path) + _check_python_bin(repository_ctx, python_bin, bin_path_key) + python_lib = _get_python_lib(repository_ctx, python_bin, lib_path_key) _check_python_lib(repository_ctx, python_lib) python_include = _get_python_include(repository_ctx, python_bin) python_include_rule = _symlink_genrule_for_dir( - repository_ctx, python_include, 'python_include', 'python_include') + repository_ctx, python_include, '{}_include'.format(variety_name), + '{}_include'.format(variety_name)) python_import_lib_genrule = "" # To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib # See https://docs.python.org/3/extending/windows.html if _is_windows(repository_ctx): python_include = _normalize_path(python_include) - python_import_lib_name = _get_python_import_lib_name( + python_import_lib_name = _get_python_import_lib_name, bin_path_key( repository_ctx, python_bin) python_import_lib_src = python_include.rsplit( '/', 1)[0] + "/libs/" + python_import_lib_name python_import_lib_genrule = _symlink_genrule_for_dir( - repository_ctx, None, '', 'python_import_lib', + repository_ctx, None, '', '{}_import_lib'.format(variety_name), [python_import_lib_src], [python_import_lib_name]) _tpl( - repository_ctx, "BUILD", { + repository_ctx, "variety", { "%{PYTHON_INCLUDE_GENRULE}": python_include_rule, "%{PYTHON_IMPORT_LIB_GENRULE}": python_import_lib_genrule, - }) - - -def _create_remote_python_repository(repository_ctx, remote_config_repo): - """Creates pointers to a remotely configured repo set up to build with Python. - """ - _tpl(repository_ctx, "remote.BUILD", { - "%{REMOTE_PYTHON_REPO}": remote_config_repo, - }, "BUILD") + "%{VARIETY_NAME}": variety_name, + }, + out="{}/BUILD".format(variety_name)) +# TODO(rbellevi): Remove def _python_autoconf_impl(repository_ctx): """Implementation of the python_autoconf repository rule.""" - if _PYTHON_CONFIG_REPO in repository_ctx.os.environ: - _create_remote_python_repository( - repository_ctx, repository_ctx.os.environ[_PYTHON_CONFIG_REPO]) - else: - _create_local_python_repository(repository_ctx) + _create_local_python_repository(repository_ctx, + "_python2", + _PYTHON2_BIN_PATH, + "python", + _PYTHON2_LIB_PATH) + _create_local_python_repository(repository_ctx, + "_python3", + _PYTHON3_BIN_PATH, + "python3", + _PYTHON3_LIB_PATH) + _tpl(repository_ctx, "BUILD") python_configure = repository_rule( implementation=_python_autoconf_impl, environ=[ _BAZEL_SH, - _PYTHON_BIN_PATH, - _PYTHON_LIB_PATH, - _PYTHON_CONFIG_REPO, + _PYTHON2_BIN_PATH, + _PYTHON2_LIB_PATH, + _PYTHON3_BIN_PATH, + _PYTHON3_LIB_PATH, ], ) """Detects and configures the local Python. +It is expected that the system have both a working Python 2 and python 3 +installation + Add the following to your WORKSPACE FILE: ```python diff --git a/third_party/py/remote.BUILD.tpl b/third_party/py/remote.BUILD.tpl deleted file mode 100644 index 1bfe1f0bf65..00000000000 --- a/third_party/py/remote.BUILD.tpl +++ /dev/null @@ -1,10 +0,0 @@ -# Adapted with modifications from tensorflow/third_party/py/ - -package(default_visibility=["//visibility:public"]) - -alias( - name="python_headers", - actual="%{REMOTE_PYTHON_REPO}:python_headers", -) - - diff --git a/third_party/py/variety.tpl b/third_party/py/variety.tpl new file mode 100644 index 00000000000..0c466d6d8f0 --- /dev/null +++ b/third_party/py/variety.tpl @@ -0,0 +1,26 @@ +package(default_visibility=["//visibility:public"]) + +# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib +# See https://docs.python.org/3/extending/windows.html +cc_import( + name="%{VARIETY_NAME}_lib", + interface_library=select({ + "//:windows": ":%{VARIETY_NAME}_import_lib", + # A placeholder for Unix platforms which makes --no_build happy. + "//conditions:default": "not-existing.lib", + }), + system_provided=1, +) + +cc_library( + name="%{VARIETY_NAME}_headers", + hdrs=[":%{VARIETY_NAME}_include"], + deps=select({ + "//:windows": [":%{VARIETY_NAME}_lib"], + "//conditions:default": [], + }), + includes=["%{VARIETY_NAME}_include"], +) + +%{PYTHON_INCLUDE_GENRULE} +%{PYTHON_IMPORT_LIB_GENRULE} diff --git a/tools/bazel.rc b/tools/bazel.rc index b24f603ddda..fcbe9337b9f 100644 --- a/tools/bazel.rc +++ b/tools/bazel.rc @@ -82,7 +82,3 @@ build:basicprof --copt=-DNDEBUG build:basicprof --copt=-O2 build:basicprof --copt=-DGRPC_BASIC_PROFILER build:basicprof --copt=-DGRPC_TIMERS_RDTSC - -build:python3 --python_path=python3 -build:python3 --python_version=PY3 -build:python3 --action_env=PYTHON_BIN_PATH=python3 From b7667478cf18cfbfb907f71b31aa12e8c7f97371 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 25 Jun 2019 10:13:21 -0400 Subject: [PATCH 43/57] bump bazel version to 0.27 --- bazel/grpc_deps.bzl | 8 ++++---- templates/tools/dockerfile/bazel.include | 2 +- tools/bazel | 2 +- tools/dockerfile/test/bazel/Dockerfile | 2 +- tools/dockerfile/test/sanity/Dockerfile | 2 +- tools/remote_build/kokoro.bazelrc | 7 +++---- tools/remote_build/manual.bazelrc | 7 +++---- tools/remote_build/rbe_common.bazelrc | 2 +- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 06323ff3f24..57021924725 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -176,11 +176,11 @@ def grpc_deps(): if "bazel_toolchains" not in native.existing_rules(): http_archive( name = "bazel_toolchains", - sha256 = "d968b414b32aa99c86977e1171645d31da2b52ac88060de3ac1e49932d5dcbf1", - strip_prefix = "bazel-toolchains-4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47", + sha256 = "872955b658113924eb1a3594b04d43238da47f4f90c17b76e8785709490dc041", + strip_prefix = "bazel-toolchains-1083686fde6032378d52b4c98044922cebde364e", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47.tar.gz", - "https://github.com/bazelbuild/bazel-toolchains/archive/4bd5df80d77aa7f4fb943dfdfad5c9056a62fb47.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz", + "https://github.com/bazelbuild/bazel-toolchains/archive/1083686fde6032378d52b4c98044922cebde364e.tar.gz", ], ) diff --git a/templates/tools/dockerfile/bazel.include b/templates/tools/dockerfile/bazel.include index adde6ed4787..12a22785623 100644 --- a/templates/tools/dockerfile/bazel.include +++ b/templates/tools/dockerfile/bazel.include @@ -2,7 +2,7 @@ # Bazel installation # Must be in sync with tools/bazel -ENV BAZEL_VERSION 0.26.0 +ENV BAZEL_VERSION 0.28.1 # The correct bazel version is already preinstalled, no need to use //tools/bazel wrapper. ENV DISABLE_BAZEL_WRAPPER 1 diff --git a/tools/bazel b/tools/bazel index 4f08d18c656..4d1d57f60d9 100755 --- a/tools/bazel +++ b/tools/bazel @@ -32,7 +32,7 @@ then exec -a "$0" "${BAZEL_REAL}" "$@" fi -VERSION=0.26.0 +VERSION=0.28.1 echo "INFO: Running bazel wrapper (see //tools/bazel for details), bazel version $VERSION will be used instead of system-wide bazel installation." diff --git a/tools/dockerfile/test/bazel/Dockerfile b/tools/dockerfile/test/bazel/Dockerfile index 7e7903359e7..7141fb9c5f1 100644 --- a/tools/dockerfile/test/bazel/Dockerfile +++ b/tools/dockerfile/test/bazel/Dockerfile @@ -52,7 +52,7 @@ RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.5.2.post1 six==1.10.0 t # Bazel installation # Must be in sync with tools/bazel -ENV BAZEL_VERSION 0.26.0 +ENV BAZEL_VERSION 0.28.1 # The correct bazel version is already preinstalled, no need to use //tools/bazel wrapper. ENV DISABLE_BAZEL_WRAPPER 1 diff --git a/tools/dockerfile/test/sanity/Dockerfile b/tools/dockerfile/test/sanity/Dockerfile index ca786e264ed..e9c1b4bee12 100644 --- a/tools/dockerfile/test/sanity/Dockerfile +++ b/tools/dockerfile/test/sanity/Dockerfile @@ -98,7 +98,7 @@ ENV CLANG_TIDY=clang-tidy # Bazel installation # Must be in sync with tools/bazel -ENV BAZEL_VERSION 0.26.0 +ENV BAZEL_VERSION 0.28.1 # The correct bazel version is already preinstalled, no need to use //tools/bazel wrapper. ENV DISABLE_BAZEL_WRAPPER 1 diff --git a/tools/remote_build/kokoro.bazelrc b/tools/remote_build/kokoro.bazelrc index 064e94b2e15..5c1b061bce3 100644 --- a/tools/remote_build/kokoro.bazelrc +++ b/tools/remote_build/kokoro.bazelrc @@ -16,13 +16,12 @@ import %workspace%/tools/remote_build/rbe_common.bazelrc -build --remote_cache=remotebuildexecution.googleapis.com -build --remote_executor=remotebuildexecution.googleapis.com -build --tls_enabled=true +build --remote_cache=grpcs://remotebuildexecution.googleapis.com +build --remote_executor=grpcs://remotebuildexecution.googleapis.com build --auth_enabled=true -build --bes_backend=buildeventservice.googleapis.com +build --bes_backend=grpcs://buildeventservice.googleapis.com build --bes_timeout=600s build --project_id=grpc-testing diff --git a/tools/remote_build/manual.bazelrc b/tools/remote_build/manual.bazelrc index fcd41f57521..c3c6af42877 100644 --- a/tools/remote_build/manual.bazelrc +++ b/tools/remote_build/manual.bazelrc @@ -17,9 +17,8 @@ import %workspace%/tools/remote_build/rbe_common.bazelrc -build --remote_cache=remotebuildexecution.googleapis.com -build --remote_executor=remotebuildexecution.googleapis.com -build --tls_enabled=true +build --remote_cache=grpcs://remotebuildexecution.googleapis.com +build --remote_executor=grpcs://remotebuildexecution.googleapis.com # Enable authentication. This will pick up application default credentials by # default. You can use --auth_credentials=some_file.json to use a service @@ -30,7 +29,7 @@ build --auth_enabled=true # Set flags for uploading to BES in order to view results in the Bazel Build # Results UI. -build --bes_backend="buildeventservice.googleapis.com" +build --bes_backend=grpcs://buildeventservice.googleapis.com build --bes_timeout=60s build --bes_results_url="https://source.cloud.google.com/results/invocations/" build --project_id=grpc-testing diff --git a/tools/remote_build/rbe_common.bazelrc b/tools/remote_build/rbe_common.bazelrc index 6baaf24732c..6236003fe17 100644 --- a/tools/remote_build/rbe_common.bazelrc +++ b/tools/remote_build/rbe_common.bazelrc @@ -87,4 +87,4 @@ build:ubsan --test_timeout=3600 # how to update the bazel toolchain for ubsan: # - check for the latest released version in https://github.com/bazelbuild/bazel-toolchains/tree/master/configs/experimental/ubuntu16_04_clang # - you might need to update the bazel_toolchains dependency in grpc_deps.bzl -build:ubsan --crosstool_top=@bazel_toolchains//configs/experimental/ubuntu16_04_clang/1.2/bazel_0.23.0/ubsan:toolchain +build:ubsan --crosstool_top=@bazel_toolchains//configs/experimental/ubuntu16_04_clang/1.2/bazel_0.28.0/ubsan:toolchain From 27990a5541db08d8cf63c433119b9744d8007b80 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 27 Aug 2019 17:47:52 -0700 Subject: [PATCH 44/57] Explicitly add python versions to examples. --- examples/python/auth/BUILD.bazel | 3 +++ examples/python/cancellation/BUILD.bazel | 3 +++ examples/python/compression/BUILD.bazel | 3 +++ examples/python/debug/BUILD.bazel | 3 +++ examples/python/errors/BUILD.bazel | 1 + examples/python/multiprocessing/BUILD | 3 +++ examples/python/wait_for_ready/BUILD.bazel | 1 + 7 files changed, 17 insertions(+) diff --git a/examples/python/auth/BUILD.bazel b/examples/python/auth/BUILD.bazel index cc454fdfdfe..72620ee46c5 100644 --- a/examples/python/auth/BUILD.bazel +++ b/examples/python/auth/BUILD.bazel @@ -39,6 +39,7 @@ py_binary( "//examples:helloworld_py_pb2", "//examples:helloworld_py_pb2_grpc", ], + python_version = "PY3", ) py_binary( @@ -51,6 +52,7 @@ py_binary( "//examples:helloworld_py_pb2", "//examples:helloworld_py_pb2_grpc", ], + python_version = "PY3", ) py_test( @@ -63,4 +65,5 @@ py_test( ":customized_auth_server", ":_credentials", ], + python_version = "PY3", ) diff --git a/examples/python/cancellation/BUILD.bazel b/examples/python/cancellation/BUILD.bazel index 17b1b20168e..b4451f60711 100644 --- a/examples/python/cancellation/BUILD.bazel +++ b/examples/python/cancellation/BUILD.bazel @@ -45,6 +45,7 @@ py_binary( "//external:six" ], srcs_version = "PY2AND3", + python_version = "PY3", ) py_library( @@ -68,6 +69,7 @@ py_binary( "//:python3": [], }), srcs_version = "PY2AND3", + python_version = "PY3", ) py_test( @@ -78,4 +80,5 @@ py_test( ":server" ], size = "small", + python_version = "PY3", ) diff --git a/examples/python/compression/BUILD.bazel b/examples/python/compression/BUILD.bazel index 9d5f6bb83ed..4141eda2ffd 100644 --- a/examples/python/compression/BUILD.bazel +++ b/examples/python/compression/BUILD.bazel @@ -21,6 +21,7 @@ py_binary( "//examples:helloworld_py_pb2_grpc", ], srcs_version = "PY2AND3", + python_version = "PY3", ) py_binary( @@ -32,6 +33,7 @@ py_binary( "//examples:helloworld_py_pb2_grpc", ], srcs_version = "PY2AND3", + python_version = "PY3", ) py_test( @@ -43,4 +45,5 @@ py_test( ":server", ], size = "small", + python_version = "PY3", ) diff --git a/examples/python/debug/BUILD.bazel b/examples/python/debug/BUILD.bazel index 657ae860ae3..332991332f8 100644 --- a/examples/python/debug/BUILD.bazel +++ b/examples/python/debug/BUILD.bazel @@ -35,6 +35,7 @@ py_binary( "//examples:helloworld_py_pb2", "//examples:helloworld_py_pb2_grpc", ], + python_version = "PY3", ) py_binary( @@ -45,6 +46,7 @@ py_binary( "//src/python/grpcio/grpc:grpcio", "//src/python/grpcio_channelz/grpc_channelz/v1:grpc_channelz", ], + python_version = "PY3", ) py_test( @@ -59,4 +61,5 @@ py_test( ":send_message", ":get_stats", ], + python_version = "PY3", ) diff --git a/examples/python/errors/BUILD.bazel b/examples/python/errors/BUILD.bazel index 4b779ddfcf1..367bd81925f 100644 --- a/examples/python/errors/BUILD.bazel +++ b/examples/python/errors/BUILD.bazel @@ -55,4 +55,5 @@ py_test( "../../../src/python/grpcio_status", "../../../src/python/grpcio_tests", ], + python_version = "PY3", ) diff --git a/examples/python/multiprocessing/BUILD b/examples/python/multiprocessing/BUILD index 490aea0c1e6..2503970bc80 100644 --- a/examples/python/multiprocessing/BUILD +++ b/examples/python/multiprocessing/BUILD @@ -42,6 +42,7 @@ py_binary( ":prime_proto_pb2_grpc", ], srcs_version = "PY3", + python_version = "PY3", ) py_binary( @@ -57,6 +58,7 @@ py_binary( "//:python3": [], }), srcs_version = "PY3", + python_version = "PY3", ) py_test( @@ -67,4 +69,5 @@ py_test( ":server" ], size = "small", + python_version = "PY3", ) diff --git a/examples/python/wait_for_ready/BUILD.bazel b/examples/python/wait_for_ready/BUILD.bazel index f074ae7bb7f..9cbddd1a6e3 100644 --- a/examples/python/wait_for_ready/BUILD.bazel +++ b/examples/python/wait_for_ready/BUILD.bazel @@ -30,4 +30,5 @@ py_test( srcs = ["test/_wait_for_ready_example_test.py"], deps = [":wait_for_ready_example",], size = "small", + python_version = "PY3", ) From 1b69538d58f037732a4a359b878b8ae8e8d296f1 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 27 Aug 2019 17:51:45 -0700 Subject: [PATCH 45/57] Switch all tests to py2and3_test --- src/python/grpcio_tests/tests/channelz/BUILD.bazel | 4 +++- src/python/grpcio_tests/tests/health_check/BUILD.bazel | 3 ++- src/python/grpcio_tests/tests/interop/BUILD.bazel | 5 +++-- src/python/grpcio_tests/tests/reflection/BUILD.bazel | 3 ++- src/python/grpcio_tests/tests/status/BUILD.bazel | 3 ++- src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel | 3 ++- .../grpcio_tests/tests/unit/framework/foundation/BUILD.bazel | 3 ++- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/python/grpcio_tests/tests/channelz/BUILD.bazel b/src/python/grpcio_tests/tests/channelz/BUILD.bazel index 63513616e77..f4d246847f7 100644 --- a/src/python/grpcio_tests/tests/channelz/BUILD.bazel +++ b/src/python/grpcio_tests/tests/channelz/BUILD.bazel @@ -1,6 +1,8 @@ package(default_visibility = ["//visibility:public"]) -py_test( +load("//bazel:python_rules.bzl", "py2and3_test") + +py2and3_test( name = "channelz_servicer_test", srcs = ["_channelz_servicer_test.py"], main = "_channelz_servicer_test.py", diff --git a/src/python/grpcio_tests/tests/health_check/BUILD.bazel b/src/python/grpcio_tests/tests/health_check/BUILD.bazel index 49f076be9a1..797b6a48e91 100644 --- a/src/python/grpcio_tests/tests/health_check/BUILD.bazel +++ b/src/python/grpcio_tests/tests/health_check/BUILD.bazel @@ -1,6 +1,7 @@ package(default_visibility = ["//visibility:public"]) +load("//bazel:python_rules.bzl", "py2and3_test") -py_test( +py2and3_test( name = "health_servicer_test", srcs = ["_health_servicer_test.py"], main = "_health_servicer_test.py", diff --git a/src/python/grpcio_tests/tests/interop/BUILD.bazel b/src/python/grpcio_tests/tests/interop/BUILD.bazel index 8ac3f7d52d5..4685852162b 100644 --- a/src/python/grpcio_tests/tests/interop/BUILD.bazel +++ b/src/python/grpcio_tests/tests/interop/BUILD.bazel @@ -1,4 +1,5 @@ load("@grpc_python_dependencies//:requirements.bzl", "requirement") +load("//bazel:python_rules.bzl", "py2and3_test") package(default_visibility = ["//visibility:public"]) @@ -80,7 +81,7 @@ py_library( ], ) -py_test( +py2and3_test( name = "_insecure_intraop_test", size = "small", srcs = ["_insecure_intraop_test.py"], @@ -99,7 +100,7 @@ py_test( ], ) -py_test( +py2and3_test( name = "_secure_intraop_test", size = "small", srcs = ["_secure_intraop_test.py"], diff --git a/src/python/grpcio_tests/tests/reflection/BUILD.bazel b/src/python/grpcio_tests/tests/reflection/BUILD.bazel index e9b56191df8..65a08c2a435 100644 --- a/src/python/grpcio_tests/tests/reflection/BUILD.bazel +++ b/src/python/grpcio_tests/tests/reflection/BUILD.bazel @@ -1,8 +1,9 @@ load("@grpc_python_dependencies//:requirements.bzl", "requirement") +load("//bazel:python_rules.bzl", "py2and3_test") package(default_visibility = ["//visibility:public"]) -py_test( +py2and3_test( name="_reflection_servicer_test", size="small", timeout="moderate", diff --git a/src/python/grpcio_tests/tests/status/BUILD.bazel b/src/python/grpcio_tests/tests/status/BUILD.bazel index b163fe3975e..0868de01acf 100644 --- a/src/python/grpcio_tests/tests/status/BUILD.bazel +++ b/src/python/grpcio_tests/tests/status/BUILD.bazel @@ -1,8 +1,9 @@ load("@grpc_python_dependencies//:requirements.bzl", "requirement") +load("//bazel:python_rules.bzl", "py2and3_test") package(default_visibility = ["//visibility:public"]) -py_test( +py2and3_test( name = "grpc_status_test", srcs = ["_grpc_status_test.py"], main = "_grpc_status_test.py", diff --git a/src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel b/src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel index 458a6b1fb8a..867649a6a50 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel +++ b/src/python/grpcio_tests/tests/unit/_cython/BUILD.bazel @@ -1,4 +1,5 @@ load("@grpc_python_dependencies//:requirements.bzl", "requirement") +load("//bazel:python_rules.bzl", "py2and3_test") package(default_visibility = ["//visibility:public"]) @@ -23,7 +24,7 @@ py_library( ) [ - py_test( + py2and3_test( name=test_file_name[:-3], size="small", srcs=[test_file_name], diff --git a/src/python/grpcio_tests/tests/unit/framework/foundation/BUILD.bazel b/src/python/grpcio_tests/tests/unit/framework/foundation/BUILD.bazel index d69186e1fde..a93249301c4 100644 --- a/src/python/grpcio_tests/tests/unit/framework/foundation/BUILD.bazel +++ b/src/python/grpcio_tests/tests/unit/framework/foundation/BUILD.bazel @@ -1,11 +1,12 @@ package(default_visibility = ["//visibility:public"]) +load("//bazel:python_rules.bzl", "py2and3_test") py_library( name = "stream_testing", srcs = ["stream_testing.py"], ) -py_test( +py2and3_test( name = "logging_pool_test", srcs = ["_logging_pool_test.py"], main = "_logging_pool_test.py", From 6dfa96524df73c5dd00ad2bf1aef1279aeb8944d Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 27 Aug 2019 17:59:39 -0700 Subject: [PATCH 46/57] Fix failing CPP test --- bazel/grpc_build_system.bzl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 23f90d0dc80..54398b66d82 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -262,13 +262,22 @@ def grpc_sh_binary(name, srcs, data = []): data = data, ) -def grpc_py_binary(name, srcs, data = [], deps = [], external_deps = [], testonly = False): +def grpc_py_binary(name, + srcs, + data = [], + deps = [], + external_deps = [], + testonly = False, + python_version = "PY2", + **kwargs): native.py_binary( name = name, srcs = srcs, testonly = testonly, data = data, deps = deps + _get_external_deps(external_deps), + python_version = python_version, + **kwargs, ) def grpc_package(name, visibility = "private", features = []): From 544ead769ddb7f2a579719953e310d088c92a376 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 27 Aug 2019 18:02:02 -0700 Subject: [PATCH 47/57] Remove explicit Python 3 testing --- tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh index f725eb7a3d7..4a48760aab1 100755 --- a/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_python_bazel_test_in_docker.sh @@ -26,9 +26,6 @@ ${name}') cd /var/local/git/grpc/test bazel test --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //src/python/... bazel test --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //examples/python/... -bazel clean --expunge -bazel test --config=python3 --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //src/python/... -bazel test --config=python3 --spawn_strategy=standalone --genrule_strategy=standalone --test_output=errors //examples/python/... # TODO(https://github.com/grpc/grpc/issues/19854): Move this to a new Kokoro # job. From 3207e623282b07c70ad07d1c9b3fbc46d2d4c394 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Tue, 27 Aug 2019 18:07:13 -0700 Subject: [PATCH 48/57] Finish todo --- third_party/py/python_configure.bzl | 1 - 1 file changed, 1 deletion(-) diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl index a2f0c7918d2..123f0b11865 100644 --- a/third_party/py/python_configure.bzl +++ b/third_party/py/python_configure.bzl @@ -277,7 +277,6 @@ def _create_local_python_repository(repository_ctx, out="{}/BUILD".format(variety_name)) -# TODO(rbellevi): Remove def _python_autoconf_impl(repository_ctx): """Implementation of the python_autoconf repository rule.""" _create_local_python_repository(repository_ctx, From abc384164ae9414dbd35507b0d06c62b83c798b1 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 28 Aug 2019 05:52:38 -0400 Subject: [PATCH 49/57] fix kwargs syntax error --- bazel/grpc_build_system.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 54398b66d82..c123a2e627d 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -277,7 +277,7 @@ def grpc_py_binary(name, data = data, deps = deps + _get_external_deps(external_deps), python_version = python_version, - **kwargs, + **kwargs ) def grpc_package(name, visibility = "private", features = []): From 1ee329187f9fdc6614a1ce1150f53dfc1bca79be Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 28 Aug 2019 08:34:39 -0400 Subject: [PATCH 50/57] enable compute_enging_creds and jwt_token_creds interop tests for managed dotnet client --- tools/run_tests/run_interop_tests.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index d35723c917e..066097dca59 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -208,8 +208,6 @@ class AspNetCoreLanguage: def unimplemented_test_cases(self): return _SKIP_COMPRESSION + \ - ['compute_engine_creds'] + \ - ['jwt_token_creds'] + \ _SKIP_GOOGLE_DEFAULT_CREDS + \ _SKIP_COMPUTE_ENGINE_CHANNEL_CREDS From 6dfe27ab0823a1dcac2953afdbf404095d7a3320 Mon Sep 17 00:00:00 2001 From: Hope Casey-Allen Date: Tue, 27 Aug 2019 15:09:17 -0700 Subject: [PATCH 51/57] Fix race in bm_chttp2_transport --- test/cpp/microbenchmarks/BUILD | 8 ++++ .../microbenchmarks/bm_chttp2_transport.cc | 40 +++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/test/cpp/microbenchmarks/BUILD b/test/cpp/microbenchmarks/BUILD index b8e9b14d4b4..fdae8246c31 100644 --- a/test/cpp/microbenchmarks/BUILD +++ b/test/cpp/microbenchmarks/BUILD @@ -27,6 +27,14 @@ grpc_cc_test( deps = ["//test/core/util:grpc_test_util"], ) +grpc_cc_binary( + name = "bm_chttp2_transport", + testonly = 1, + srcs = ["bm_chttp2_transport.cc"], + tags = ["no_windows"], + deps = [":helpers"], +) + grpc_cc_library( name = "helpers", testonly = 1, diff --git a/test/cpp/microbenchmarks/bm_chttp2_transport.cc b/test/cpp/microbenchmarks/bm_chttp2_transport.cc index da3357304ba..dc3d76ee38e 100644 --- a/test/cpp/microbenchmarks/bm_chttp2_transport.cc +++ b/test/cpp/microbenchmarks/bm_chttp2_transport.cc @@ -239,7 +239,7 @@ class Stream { grpc_transport_destroy_stream(stream->f_->transport(), static_cast(stream->stream_), stream->destroy_closure_); - gpr_event_set(&stream->done_, (void*)1); + gpr_event_set(&stream->done_, (void*)(1)); } Fixture* f_; @@ -254,6 +254,7 @@ class Stream { //////////////////////////////////////////////////////////////////////////////// // Benchmarks // +std::vector> done_events; static void BM_StreamCreateDestroy(benchmark::State& state) { TrackCounters track_counters; @@ -380,15 +381,24 @@ static void BM_TransportEmptyOp(benchmark::State& state) { reset_op(); op.cancel_stream = true; op_payload.cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; + gpr_event* stream_cancel_done = new gpr_event; + gpr_event_init(stream_cancel_done); + std::unique_ptr stream_cancel_closure = + MakeClosure([&](grpc_error* error) { + GPR_ASSERT(error == GRPC_ERROR_NONE); + gpr_event_set(stream_cancel_done, (void*)(1)); + }); + op.on_complete = stream_cancel_closure.get(); s->Op(&op); + f.FlushExecCtx(); + gpr_event_wait(stream_cancel_done, gpr_inf_future(GPR_CLOCK_REALTIME)); + done_events.emplace_back(stream_cancel_done); s->DestroyThen(MakeOnceClosure([s](grpc_error* error) { delete s; })); f.FlushExecCtx(); track_counters.Finish(state); } BENCHMARK(BM_TransportEmptyOp); -std::vector> done_events; - static void BM_TransportStreamSend(benchmark::State& state) { TrackCounters track_counters; grpc_core::ExecCtx exec_ctx; @@ -424,7 +434,7 @@ static void BM_TransportStreamSend(benchmark::State& state) { std::unique_ptr c = MakeClosure([&](grpc_error* error) { if (!state.KeepRunning()) { - gpr_event_set(bm_done, (void*)1); + gpr_event_set(bm_done, (void*)(1)); return; } grpc_slice_buffer send_buffer; @@ -455,7 +465,18 @@ static void BM_TransportStreamSend(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; + gpr_event* stream_cancel_done = new gpr_event; + gpr_event_init(stream_cancel_done); + std::unique_ptr stream_cancel_closure = + MakeClosure([&](grpc_error* error) { + GPR_ASSERT(error == GRPC_ERROR_NONE); + gpr_event_set(stream_cancel_done, (void*)(1)); + }); + op.on_complete = stream_cancel_closure.get(); s->Op(&op); + f.FlushExecCtx(); + gpr_event_wait(stream_cancel_done, gpr_inf_future(GPR_CLOCK_REALTIME)); + done_events.emplace_back(stream_cancel_done); s->DestroyThen(MakeOnceClosure([s](grpc_error* error) { delete s; })); f.FlushExecCtx(); track_counters.Finish(state); @@ -629,7 +650,18 @@ static void BM_TransportStreamRecv(benchmark::State& state) { reset_op(); op.cancel_stream = true; op.payload->cancel_stream.cancel_error = GRPC_ERROR_CANCELLED; + gpr_event* stream_cancel_done = new gpr_event; + gpr_event_init(stream_cancel_done); + std::unique_ptr stream_cancel_closure = + MakeClosure([&](grpc_error* error) { + GPR_ASSERT(error == GRPC_ERROR_NONE); + gpr_event_set(stream_cancel_done, (void*)(1)); + }); + op.on_complete = stream_cancel_closure.get(); s->Op(&op); + f.FlushExecCtx(); + gpr_event_wait(stream_cancel_done, gpr_inf_future(GPR_CLOCK_REALTIME)); + done_events.emplace_back(stream_cancel_done); s->DestroyThen(MakeOnceClosure([s](grpc_error* error) { delete s; })); grpc_metadata_batch_destroy(&b); grpc_metadata_batch_destroy(&b_recv); From a451a3a94b09a78d4511dd13500bd9da96696d50 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 28 Aug 2019 10:18:14 -0700 Subject: [PATCH 52/57] Rename function --- third_party/py/python_configure.bzl | 31 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl index 123f0b11865..70380e9dde9 100644 --- a/third_party/py/python_configure.bzl +++ b/third_party/py/python_configure.bzl @@ -241,12 +241,11 @@ def _get_python_import_lib_name(repository_ctx, python_bin, bin_path_key): return result.stdout.splitlines()[0] -# TODO(rbellevi): Rename. -def _create_local_python_repository(repository_ctx, - variety_name, - bin_path_key, - default_bin_path, - lib_path_key): +def _create_single_version_package(repository_ctx, + variety_name, + bin_path_key, + default_bin_path, + lib_path_key): """Creates the repository containing files set up to build with Python.""" python_bin = _get_python_bin(repository_ctx, bin_path_key, default_bin_path) _check_python_bin(repository_ctx, python_bin, bin_path_key) @@ -279,16 +278,16 @@ def _create_local_python_repository(repository_ctx, def _python_autoconf_impl(repository_ctx): """Implementation of the python_autoconf repository rule.""" - _create_local_python_repository(repository_ctx, - "_python2", - _PYTHON2_BIN_PATH, - "python", - _PYTHON2_LIB_PATH) - _create_local_python_repository(repository_ctx, - "_python3", - _PYTHON3_BIN_PATH, - "python3", - _PYTHON3_LIB_PATH) + _create_single_version_package(repository_ctx, + "_python2", + _PYTHON2_BIN_PATH, + "python", + _PYTHON2_LIB_PATH) + _create_single_version_package(repository_ctx, + "_python3", + _PYTHON3_BIN_PATH, + "python3", + _PYTHON3_LIB_PATH) _tpl(repository_ctx, "BUILD") From d3cd387e03e3cbf99f71c144e371aeade4ad7357 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 28 Aug 2019 10:43:01 -0700 Subject: [PATCH 53/57] Bump rules_apple --- bazel/grpc_deps.bzl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index 57021924725..6bbb960b6c3 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -221,10 +221,11 @@ def grpc_deps(): ) if "build_bazel_rules_apple" not in native.existing_rules(): - git_repository( + http_archive( name = "build_bazel_rules_apple", - remote = "https://github.com/bazelbuild/rules_apple.git", - tag = "0.17.2", + url = "https://github.com/bazelbuild/rules_apple/archive/b869b0d3868d78a1d4ffd866ccb304fb68aa12c3.tar.gz", + strip_prefix = "rules_apple-b869b0d3868d78a1d4ffd866ccb304fb68aa12c3", + sha256 = "bdc8e66e70b8a75da23b79f1f8c6207356df07d041d96d2189add7ee0780cf4e", ) grpc_python_deps() From d1f4456dc656264c3413dd9596b910cad3539e33 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 28 Aug 2019 11:37:59 -0700 Subject: [PATCH 54/57] Revert "Merge pull request #19704 from muxi/isolate-call-implementation-2" This reverts commit ac5f8062dd4e9d903a42f41219b5323eec0908be, reversing changes made to 8ae549431ce2f3c009b3a297570f40339f05f699. --- bazel/grpc_build_system.bzl | 11 +- gRPC-ProtoRPC.podspec | 30 +- gRPC-RxLibrary.podspec | 17 - gRPC.podspec | 116 +-- src/compiler/objective_c_generator.cc | 97 +- src/compiler/objective_c_generator.h | 14 +- src/compiler/objective_c_plugin.cc | 60 +- src/objective-c/BUILD | 244 ++--- .../GRPCClient/GRPCCall+ChannelArg.h | 2 +- .../GRPCClient/GRPCCall+ChannelArg.m | 4 +- .../GRPCClient/GRPCCall+ChannelCredentials.h | 2 +- .../GRPCClient/GRPCCall+ChannelCredentials.m | 2 +- src/objective-c/GRPCClient/GRPCCall+Cronet.h | 13 +- src/objective-c/GRPCClient/GRPCCall+Cronet.m | 4 +- src/objective-c/GRPCClient/GRPCCall+GID.h | 2 +- src/objective-c/GRPCClient/GRPCCall+OAuth2.h | 4 +- src/objective-c/GRPCClient/GRPCCall+Tests.h | 2 +- src/objective-c/GRPCClient/GRPCCall+Tests.m | 2 +- src/objective-c/GRPCClient/GRPCCall.h | 240 ++++- src/objective-c/GRPCClient/GRPCCall.m | 867 +++++++++++++++--- src/objective-c/GRPCClient/GRPCCallLegacy.h | 136 --- src/objective-c/GRPCClient/GRPCCallLegacy.m | 677 -------------- src/objective-c/GRPCClient/GRPCCallOptions.h | 82 +- src/objective-c/GRPCClient/GRPCCallOptions.m | 27 +- src/objective-c/GRPCClient/GRPCDispatchable.h | 30 - src/objective-c/GRPCClient/GRPCInterceptor.h | 32 +- src/objective-c/GRPCClient/GRPCInterceptor.m | 265 ++---- src/objective-c/GRPCClient/GRPCTransport.h | 82 -- src/objective-c/GRPCClient/GRPCTransport.m | 142 --- src/objective-c/GRPCClient/GRPCTypes.h | 187 ---- .../internal_testing/GRPCCall+InternalTests.m | 2 +- .../private/{GRPCCore => }/ChannelArgsUtil.h | 0 .../private/{GRPCCore => }/ChannelArgsUtil.m | 0 .../private/{GRPCCore => }/GRPCCall+V2API.h | 6 + .../private/{GRPCCore => }/GRPCCallInternal.h | 14 +- .../private/{GRPCCore => }/GRPCCallInternal.m | 140 ++- .../private/{GRPCCore => }/GRPCChannel.h | 0 .../private/{GRPCCore => }/GRPCChannel.m | 72 +- .../{GRPCCore => }/GRPCChannelFactory.h | 0 .../{GRPCCore => }/GRPCChannelPool+Test.h | 0 .../private/{GRPCCore => }/GRPCChannelPool.h | 2 + .../private/{GRPCCore => }/GRPCChannelPool.m | 5 +- .../{GRPCCore => }/GRPCCompletionQueue.h | 0 .../{GRPCCore => }/GRPCCompletionQueue.m | 0 .../GRPCCoreCronet/GRPCCoreCronetFactory.h | 32 - .../GRPCCoreCronet/GRPCCoreCronetFactory.m | 54 -- .../private/GRPCCore/GRPCCoreFactory.h | 45 - .../private/GRPCCore/GRPCCoreFactory.m | 90 -- .../GRPCCronetChannelFactory.h | 2 +- .../GRPCCronetChannelFactory.m | 24 +- .../private/{GRPCCore => }/GRPCHost.h | 0 .../private/{GRPCCore => }/GRPCHost.m | 35 +- .../GRPCInsecureChannelFactory.h | 0 .../GRPCInsecureChannelFactory.m | 0 .../private/{GRPCCore => }/GRPCOpBatchLog.h | 0 .../private/{GRPCCore => }/GRPCOpBatchLog.m | 0 .../GRPCReachabilityFlagNames.xmacro.h | 0 .../{GRPCCore => }/GRPCRequestHeaders.h | 2 +- .../{GRPCCore => }/GRPCRequestHeaders.m | 0 .../{GRPCCore => }/GRPCSecureChannelFactory.h | 0 .../{GRPCCore => }/GRPCSecureChannelFactory.m | 0 .../private/GRPCTransport+Private.h | 65 -- .../private/GRPCTransport+Private.m | 131 --- .../private/{GRPCCore => }/GRPCWrappedCall.h | 0 .../private/{GRPCCore => }/GRPCWrappedCall.m | 0 .../private/{GRPCCore => }/NSData+GRPC.h | 0 .../private/{GRPCCore => }/NSData+GRPC.m | 0 .../{GRPCCore => }/NSDictionary+GRPC.h | 0 .../{GRPCCore => }/NSDictionary+GRPC.m | 0 .../private/{GRPCCore => }/NSError+GRPC.h | 0 .../private/{GRPCCore => }/NSError+GRPC.m | 3 +- .../GRPCClient/{ => private}/version.h | 0 src/objective-c/ProtoRPC/ProtoRPC.h | 38 +- src/objective-c/ProtoRPC/ProtoRPC.m | 91 ++ src/objective-c/ProtoRPC/ProtoRPCLegacy.h | 67 -- src/objective-c/ProtoRPC/ProtoRPCLegacy.m | 121 --- src/objective-c/ProtoRPC/ProtoService.h | 29 +- src/objective-c/ProtoRPC/ProtoService.m | 42 +- src/objective-c/ProtoRPC/ProtoServiceLegacy.h | 23 - src/objective-c/ProtoRPC/ProtoServiceLegacy.m | 71 -- .../tvOS-sample/tvOS-sample/ViewController.m | 2 - .../WatchKit-Extension/InterfaceController.m | 2 - src/objective-c/tests/BUILD | 8 + src/objective-c/tests/ConfigureCronet.h | 4 + src/objective-c/tests/ConfigureCronet.m | 4 + .../InteropTestsRemoteWithCronet.m | 12 +- .../tests/InteropTests/InteropTests.h | 13 +- .../tests/InteropTests/InteropTests.m | 268 +++--- .../InteropTests/InteropTestsLocalCleartext.m | 5 +- .../tests/InteropTests/InteropTestsLocalSSL.m | 5 +- .../InteropTestsMultipleChannels.m | 3 +- .../tests/InteropTests/InteropTestsRemote.m | 6 + src/objective-c/tests/Podfile | 24 +- .../tests/Tests.xcodeproj/project.pbxproj | 29 +- .../xcschemes/InteropTests.xcscheme | 8 +- .../tests/UnitTests/ChannelPoolTest.m | 6 +- .../tests/UnitTests/ChannelTests.m | 10 +- .../tests/UnitTests/NSErrorUnitTests.m | 2 +- templates/gRPC-ProtoRPC.podspec.template | 30 +- templates/gRPC-RxLibrary.podspec.template | 17 - templates/gRPC.podspec.template | 116 +-- .../{ => private}/version.h.template | 0 102 files changed, 1922 insertions(+), 3251 deletions(-) delete mode 100644 src/objective-c/GRPCClient/GRPCCallLegacy.h delete mode 100644 src/objective-c/GRPCClient/GRPCCallLegacy.m delete mode 100644 src/objective-c/GRPCClient/GRPCDispatchable.h delete mode 100644 src/objective-c/GRPCClient/GRPCTransport.h delete mode 100644 src/objective-c/GRPCClient/GRPCTransport.m delete mode 100644 src/objective-c/GRPCClient/GRPCTypes.h rename src/objective-c/GRPCClient/private/{GRPCCore => }/ChannelArgsUtil.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/ChannelArgsUtil.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCCall+V2API.h (79%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCCallInternal.h (70%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCCallInternal.m (69%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannel.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannel.m (78%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannelFactory.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannelPool+Test.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannelPool.h (98%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCChannelPool.m (98%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCCompletionQueue.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCCompletionQueue.m (100%) delete mode 100644 src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m delete mode 100644 src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m rename src/objective-c/GRPCClient/private/{GRPCCore/GRPCCoreCronet => }/GRPCCronetChannelFactory.h (96%) rename src/objective-c/GRPCClient/private/{GRPCCore/GRPCCoreCronet => }/GRPCCronetChannelFactory.m (76%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCHost.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCHost.m (82%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCInsecureChannelFactory.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCInsecureChannelFactory.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCOpBatchLog.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCOpBatchLog.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCReachabilityFlagNames.xmacro.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCRequestHeaders.h (95%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCRequestHeaders.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCSecureChannelFactory.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCSecureChannelFactory.m (100%) delete mode 100644 src/objective-c/GRPCClient/private/GRPCTransport+Private.h delete mode 100644 src/objective-c/GRPCClient/private/GRPCTransport+Private.m rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCWrappedCall.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/GRPCWrappedCall.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSData+GRPC.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSData+GRPC.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSDictionary+GRPC.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSDictionary+GRPC.m (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSError+GRPC.h (100%) rename src/objective-c/GRPCClient/private/{GRPCCore => }/NSError+GRPC.m (96%) rename src/objective-c/GRPCClient/{ => private}/version.h (100%) delete mode 100644 src/objective-c/ProtoRPC/ProtoRPCLegacy.h delete mode 100644 src/objective-c/ProtoRPC/ProtoRPCLegacy.m delete mode 100644 src/objective-c/ProtoRPC/ProtoServiceLegacy.h delete mode 100644 src/objective-c/ProtoRPC/ProtoServiceLegacy.m rename templates/src/objective-c/GRPCClient/{ => private}/version.h.template (100%) diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index 23f90d0dc80..f386b87b583 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -24,6 +24,7 @@ # load("//bazel:cc_grpc_library.bzl", "cc_grpc_library") +load("@build_bazel_rules_apple//apple:resources.bzl", "apple_resource_bundle") load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library") load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test") @@ -238,13 +239,19 @@ def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], da ) def grpc_generate_one_off_targets(): + apple_resource_bundle( + # The choice of name is signicant here, since it determines the bundle name. + name = "gRPCCertificates", + resources = ["etc/roots.pem"], + ) + # In open-source, grpc_objc* libraries depend directly on //:grpc native.alias( name = "grpc_objc", actual = "//:grpc", ) -def grpc_generate_objc_one_off_targets(): +def grpc_objc_use_cronet_config(): pass def grpc_sh_test(name, srcs, args = [], data = []): @@ -289,7 +296,7 @@ def grpc_package(name, visibility = "private", features = []): def grpc_objc_library( name, - srcs = [], + srcs, hdrs = [], textual_hdrs = [], data = [], diff --git a/gRPC-ProtoRPC.podspec b/gRPC-ProtoRPC.podspec index 4c5ebb36562..57dac5a10e5 100644 --- a/gRPC-ProtoRPC.podspec +++ b/gRPC-ProtoRPC.podspec @@ -42,40 +42,22 @@ Pod::Spec.new do |s| s.module_name = name s.header_dir = name - s.default_subspec = 'Main', 'Legacy', 'Legacy-Header' + src_dir = 'src/objective-c/ProtoRPC' - s.subspec 'Legacy-Header' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.public_header_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.h" - ss.source_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.h" - end + s.default_subspec = 'Main' s.subspec 'Main' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.dependency "#{s.name}/Legacy-Header", version - ss.dependency 'gRPC/Interface', version - ss.dependency 'Protobuf', '~> 3.0' - - ss.source_files = "src/objective-c/ProtoRPC/ProtoMethod.{h,m}", - "src/objective-c/ProtoRPC/ProtoRPC.{h,m}", - "src/objective-c/ProtoRPC/ProtoService.{h,m}" - end - - s.subspec 'Legacy' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.dependency "#{s.name}/Main", version - ss.dependency "#{s.name}/Legacy-Header", version - ss.dependency 'gRPC/GRPCCore', version + ss.header_mappings_dir = "#{src_dir}" + ss.dependency 'gRPC', version ss.dependency 'gRPC-RxLibrary', version ss.dependency 'Protobuf', '~> 3.0' - ss.source_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.m", - "src/objective-c/ProtoRPC/ProtoServiceLegacy.m" + ss.source_files = "#{src_dir}/*.{h,m}" end # CFStream is now default. Leaving this subspec only for compatibility purpose. s.subspec 'CFStream' do |ss| - ss.dependency "#{s.name}/Legacy", version + ss.dependency "#{s.name}/Main", version end s.pod_target_xcconfig = { diff --git a/gRPC-RxLibrary.podspec b/gRPC-RxLibrary.podspec index 2e412cf67d6..9666c3c1b98 100644 --- a/gRPC-RxLibrary.podspec +++ b/gRPC-RxLibrary.podspec @@ -42,23 +42,6 @@ Pod::Spec.new do |s| s.module_name = name s.header_dir = name - s.default_subspec = 'Interface', 'Implementation' - - src_dir = 'src/objective-c/RxLibrary' - s.subspec 'Interface' do |ss| - ss.header_mappings_dir = "#{src_dir}" - ss.source_files = "#{src_dir}/*.h" - ss.public_header_files = "#{src_dir}/*.h" - end - - s.subspec 'Implementation' do |ss| - ss.header_mappings_dir = "#{src_dir}" - ss.source_files = "#{src_dir}/*.m", "#{src_dir}/**/*.{h,m}" - ss.private_header_files = "#{src_dir}/**/*.h" - - ss.dependency "#{s.name}/Interface" - end - src_dir = 'src/objective-c/RxLibrary' s.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}" s.private_header_files = "#{src_dir}/private/*.h" diff --git a/gRPC.podspec b/gRPC.podspec index e18adcd276e..09baf1e3b4b 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -41,7 +41,13 @@ Pod::Spec.new do |s| s.module_name = name s.header_dir = name - s.default_subspec = 'Interface', 'GRPCCore', 'Interface-Legacy' + src_dir = 'src/objective-c/GRPCClient' + + s.dependency 'gRPC-RxLibrary', version + s.default_subspec = 'Main' + + # Certificates, to be able to establish TLS connections: + s.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] } s.pod_target_xcconfig = { # This is needed by all pods that depend on gRPC-RxLibrary: @@ -49,103 +55,29 @@ Pod::Spec.new do |s| 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', } - s.subspec 'Interface-Legacy' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "src/objective-c/GRPCClient/GRPCCallLegacy.h", - "src/objective-c/GRPCClient/GRPCTypes.h" - - ss.source_files = "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "src/objective-c/GRPCClient/GRPCCallLegacy.h", - "src/objective-c/GRPCClient/GRPCTypes.h" - ss.dependency "gRPC-RxLibrary/Interface", version - end + s.subspec 'Main' do |ss| + ss.header_mappings_dir = "#{src_dir}" - s.subspec 'Interface' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = 'src/objective-c/GRPCClient/GRPCCall.h', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.h', - 'src/objective-c/GRPCClient/GRPCCallOptions.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.h', - 'src/objective-c/GRPCClient/GRPCTransport.h', - 'src/objective-c/GRPCClient/GRPCDispatchable.h', - 'src/objective-c/GRPCClient/version.h' - - ss.source_files = 'src/objective-c/GRPCClient/GRPCCall.h', - 'src/objective-c/GRPCClient/GRPCCall.m', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.h', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.m', - 'src/objective-c/GRPCClient/GRPCCallOptions.h', - 'src/objective-c/GRPCClient/GRPCCallOptions.m', - 'src/objective-c/GRPCClient/GRPCDispatchable.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.m', - 'src/objective-c/GRPCClient/GRPCTransport.h', - 'src/objective-c/GRPCClient/GRPCTransport.m', - 'src/objective-c/GRPCClient/internal/*.h', - 'src/objective-c/GRPCClient/private/GRPCTransport+Private.h', - 'src/objective-c/GRPCClient/private/GRPCTransport+Private.m', - 'src/objective-c/GRPCClient/version.h' - - ss.dependency "#{s.name}/Interface-Legacy", version - end + ss.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}" + ss.exclude_files = "#{src_dir}/GRPCCall+GID.{h,m}" + ss.private_header_files = "#{src_dir}/private/*.h", "#{src_dir}/internal/*.h" - s.subspec 'GRPCCore' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.h', - 'src/objective-c/GRPCClient/GRPCCall+Tests.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.h', - 'src/objective-c/GRPCClient/internal_testing/*.h' - ss.private_header_files = 'src/objective-c/GRPCClient/private/GRPCCore/*.h' - ss.source_files = 'src/objective-c/GRPCClient/internal_testing/*.{h,m}', - 'src/objective-c/GRPCClient/private/GRPCCore/*.{h,m}', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.m', - 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.m', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.h', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.m', - 'src/objective-c/GRPCClient/GRPCCall+Tests.h', - 'src/objective-c/GRPCClient/GRPCCall+Tests.m', - 'src/objective-c/GRPCClient/GRPCCallLegacy.m' - - # Certificates, to be able to establish TLS connections: - ss.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] } - - ss.dependency "#{s.name}/Interface-Legacy", version - ss.dependency "#{s.name}/Interface", version ss.dependency 'gRPC-Core', version - ss.dependency 'gRPC-RxLibrary', version - end - - s.subspec 'GRPCCoreCronet' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.source_files = 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.m', - 'src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/*.{h,m}' - ss.dependency "#{s.name}/GRPCCore", version - ss.dependency 'gRPC-Core/Cronet-Implementation', version - ss.dependency 'CronetFramework' end # CFStream is now default. Leaving this subspec only for compatibility purpose. s.subspec 'CFStream' do |ss| - ss.dependency "#{s.name}/GRPCCore", version + ss.dependency "#{s.name}/Main", version + end + + s.subspec 'GID' do |ss| + ss.ios.deployment_target = '7.0' + + ss.header_mappings_dir = "#{src_dir}" + + ss.source_files = "#{src_dir}/GRPCCall+GID.{h,m}" + + ss.dependency "#{s.name}/Main", version + ss.dependency 'Google/SignIn' end end diff --git a/src/compiler/objective_c_generator.cc b/src/compiler/objective_c_generator.cc index ed262308aba..24845ecdb06 100644 --- a/src/compiler/objective_c_generator.cc +++ b/src/compiler/objective_c_generator.cc @@ -238,21 +238,19 @@ void PrintV2Implementation(Printer* printer, const MethodDescriptor* method, } void PrintMethodImplementations(Printer* printer, - const MethodDescriptor* method, - const Parameters& generator_params) { + const MethodDescriptor* method) { map< ::grpc::string, ::grpc::string> vars = GetMethodVars(method); PrintProtoRpcDeclarationAsPragma(printer, method, vars); - if (!generator_params.no_v1_compatibility) { - // TODO(jcanizales): Print documentation from the method. - PrintSimpleSignature(printer, method, vars); - PrintSimpleImplementation(printer, method, vars); + // TODO(jcanizales): Print documentation from the method. + printer->Print("// Deprecated methods.\n"); + PrintSimpleSignature(printer, method, vars); + PrintSimpleImplementation(printer, method, vars); - printer->Print("// Returns a not-yet-started RPC object.\n"); - PrintAdvancedSignature(printer, method, vars); - PrintAdvancedImplementation(printer, method, vars); - } + printer->Print("// Returns a not-yet-started RPC object.\n"); + PrintAdvancedSignature(printer, method, vars); + PrintAdvancedImplementation(printer, method, vars); PrintV2Signature(printer, method, vars); PrintV2Implementation(printer, method, vars); @@ -278,12 +276,9 @@ void PrintMethodImplementations(Printer* printer, return output; } -::grpc::string GetProtocol(const ServiceDescriptor* service, - const Parameters& generator_params) { +::grpc::string GetProtocol(const ServiceDescriptor* service) { ::grpc::string output; - if (generator_params.no_v1_compatibility) return output; - // Scope the output stream so it closes and finalizes output to the string. grpc::protobuf::io::StringOutputStream output_stream(&output); Printer printer(&output_stream, '$'); @@ -326,8 +321,7 @@ void PrintMethodImplementations(Printer* printer, return output; } -::grpc::string GetInterface(const ServiceDescriptor* service, - const Parameters& generator_params) { +::grpc::string GetInterface(const ServiceDescriptor* service) { ::grpc::string output; // Scope the output stream so it closes and finalizes output to the string. @@ -344,11 +338,7 @@ void PrintMethodImplementations(Printer* printer, " */\n"); printer.Print(vars, "@interface $service_class$ :" - " GRPCProtoService<$service_class$2"); - if (!generator_params.no_v1_compatibility) { - printer.Print(vars, ", $service_class$"); - } - printer.Print(">\n"); + " GRPCProtoService<$service_class$, $service_class$2>\n"); printer.Print( "- (instancetype)initWithHost:(NSString *)host " "callOptions:(GRPCCallOptions " @@ -357,20 +347,17 @@ void PrintMethodImplementations(Printer* printer, printer.Print( "+ (instancetype)serviceWithHost:(NSString *)host " "callOptions:(GRPCCallOptions *_Nullable)callOptions;\n"); - if (!generator_params.no_v1_compatibility) { - printer.Print( - "// The following methods belong to a set of old APIs that have been " - "deprecated.\n"); - printer.Print("- (instancetype)initWithHost:(NSString *)host;\n"); - printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n"); - } + printer.Print( + "// The following methods belong to a set of old APIs that have been " + "deprecated.\n"); + printer.Print("- (instancetype)initWithHost:(NSString *)host;\n"); + printer.Print("+ (instancetype)serviceWithHost:(NSString *)host;\n"); printer.Print("@end\n"); return output; } -::grpc::string GetSource(const ServiceDescriptor* service, - const Parameters& generator_params) { +::grpc::string GetSource(const ServiceDescriptor* service) { ::grpc::string output; { // Scope the output stream so it closes and finalizes output to the string. @@ -394,28 +381,22 @@ void PrintMethodImplementations(Printer* printer, " packageName:@\"$package$\"\n" " serviceName:@\"$service_name$\"\n" " callOptions:callOptions];\n" - "}\n\n"); - if (!generator_params.no_v1_compatibility) { - printer.Print(vars, - "- (instancetype)initWithHost:(NSString *)host {\n" - " return [super initWithHost:host\n" - " packageName:@\"$package$\"\n" - " serviceName:@\"$service_name$\"];\n" - "}\n\n"); - } - printer.Print("#pragma clang diagnostic pop\n\n"); - - if (!generator_params.no_v1_compatibility) { - printer.Print( - "// Override superclass initializer to disallow different" - " package and service names.\n" - "- (instancetype)initWithHost:(NSString *)host\n" - " packageName:(NSString *)packageName\n" - " serviceName:(NSString *)serviceName {\n" - " return [self initWithHost:host];\n" - "}\n\n"); - } + "}\n\n" + "- (instancetype)initWithHost:(NSString *)host {\n" + " return [super initWithHost:host\n" + " packageName:@\"$package$\"\n" + " serviceName:@\"$service_name$\"];\n" + "}\n\n" + "#pragma clang diagnostic pop\n\n"); + printer.Print( + "// Override superclass initializer to disallow different" + " package and service names.\n" + "- (instancetype)initWithHost:(NSString *)host\n" + " packageName:(NSString *)packageName\n" + " serviceName:(NSString *)serviceName {\n" + " return [self initWithHost:host];\n" + "}\n\n" "- (instancetype)initWithHost:(NSString *)host\n" " packageName:(NSString *)packageName\n" " serviceName:(NSString *)serviceName\n" @@ -423,14 +404,11 @@ void PrintMethodImplementations(Printer* printer, " return [self initWithHost:host callOptions:callOptions];\n" "}\n\n"); - printer.Print("#pragma mark - Class Methods\n\n"); - if (!generator_params.no_v1_compatibility) { - printer.Print( - "+ (instancetype)serviceWithHost:(NSString *)host {\n" - " return [[self alloc] initWithHost:host];\n" - "}\n\n"); - } printer.Print( + "#pragma mark - Class Methods\n\n" + "+ (instancetype)serviceWithHost:(NSString *)host {\n" + " return [[self alloc] initWithHost:host];\n" + "}\n\n" "+ (instancetype)serviceWithHost:(NSString *)host " "callOptions:(GRPCCallOptions *_Nullable)callOptions {\n" " return [[self alloc] initWithHost:host callOptions:callOptions];\n" @@ -439,8 +417,7 @@ void PrintMethodImplementations(Printer* printer, printer.Print("#pragma mark - Method Implementations\n\n"); for (int i = 0; i < service->method_count(); i++) { - PrintMethodImplementations(&printer, service->method(i), - generator_params); + PrintMethodImplementations(&printer, service->method(i)); } printer.Print("@end\n"); diff --git a/src/compiler/objective_c_generator.h b/src/compiler/objective_c_generator.h index 518962fceee..c171e5bf772 100644 --- a/src/compiler/objective_c_generator.h +++ b/src/compiler/objective_c_generator.h @@ -23,11 +23,6 @@ namespace grpc_objective_c_generator { -struct Parameters { - // Do not generate V1 interface and implementation - bool no_v1_compatibility; -}; - using ::grpc::protobuf::FileDescriptor; using ::grpc::protobuf::FileDescriptor; using ::grpc::protobuf::ServiceDescriptor; @@ -39,8 +34,7 @@ string GetAllMessageClasses(const FileDescriptor* file); // Returns the content to be included defining the @protocol segment at the // insertion point of the generated implementation file. This interface is // legacy and for backwards compatibility. -string GetProtocol(const ServiceDescriptor* service, - const Parameters& generator_params); +string GetProtocol(const ServiceDescriptor* service); // Returns the content to be included defining the @protocol segment at the // insertion point of the generated implementation file. @@ -48,13 +42,11 @@ string GetV2Protocol(const ServiceDescriptor* service); // Returns the content to be included defining the @interface segment at the // insertion point of the generated implementation file. -string GetInterface(const ServiceDescriptor* service, - const Parameters& generator_params); +string GetInterface(const ServiceDescriptor* service); // Returns the content to be included in the "global_scope" insertion point of // the generated implementation file. -string GetSource(const ServiceDescriptor* service, - const Parameters& generator_params); +string GetSource(const ServiceDescriptor* service); } // namespace grpc_objective_c_generator diff --git a/src/compiler/objective_c_plugin.cc b/src/compiler/objective_c_plugin.cc index a08064a08bd..f398033f6db 100644 --- a/src/compiler/objective_c_plugin.cc +++ b/src/compiler/objective_c_plugin.cc @@ -111,22 +111,6 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string file_name = google::protobuf::compiler::objectivec::FilePath(file); - grpc_objective_c_generator::Parameters generator_params; - generator_params.no_v1_compatibility = false; - - if (!parameter.empty()) { - std::vector parameters_list = - grpc_generator::tokenize(parameter, ","); - for (auto parameter_string = parameters_list.begin(); - parameter_string != parameters_list.end(); parameter_string++) { - std::vector param = - grpc_generator::tokenize(*parameter_string, "="); - if (param[0] == "no_v1_compatibility") { - generator_params.no_v1_compatibility = true; - } - } - } - { // Generate .pbrpc.h @@ -137,25 +121,18 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { imports = FrameworkImport(file_name + ".pbobjc.h", framework); } - ::grpc::string system_imports = - SystemImport("ProtoRPC/ProtoService.h") + - (generator_params.no_v1_compatibility - ? SystemImport("ProtoRPC/ProtoRPC.h") - : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); - if (!generator_params.no_v1_compatibility) { - system_imports += SystemImport("RxLibrary/GRXWriteable.h") + - SystemImport("RxLibrary/GRXWriter.h"); - } + ::grpc::string system_imports = SystemImport("ProtoRPC/ProtoService.h") + + SystemImport("ProtoRPC/ProtoRPC.h") + + SystemImport("RxLibrary/GRXWriteable.h") + + SystemImport("RxLibrary/GRXWriter.h"); ::grpc::string forward_declarations = + "@class GRPCProtoCall;\n" "@class GRPCUnaryProtoCall;\n" "@class GRPCStreamingProtoCall;\n" "@class GRPCCallOptions;\n" - "@protocol GRPCProtoResponseHandler;\n"; - if (!generator_params.no_v1_compatibility) { - forward_declarations += "@class GRPCProtoCall;\n"; - } - forward_declarations += "\n"; + "@protocol GRPCProtoResponseHandler;\n" + "\n"; ::grpc::string class_declarations = grpc_objective_c_generator::GetAllMessageClasses(file); @@ -175,15 +152,13 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string protocols; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - protocols += - grpc_objective_c_generator::GetProtocol(service, generator_params); + protocols += grpc_objective_c_generator::GetProtocol(service); } ::grpc::string interfaces; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - interfaces += - grpc_objective_c_generator::GetInterface(service, generator_params); + interfaces += grpc_objective_c_generator::GetInterface(service); } Write(context, file_name + ".pbrpc.h", @@ -203,16 +178,14 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string imports; if (framework.empty()) { imports = LocalImport(file_name + ".pbrpc.h") + - LocalImport(file_name + ".pbobjc.h"); + LocalImport(file_name + ".pbobjc.h") + + SystemImport("ProtoRPC/ProtoRPC.h") + + SystemImport("RxLibrary/GRXWriter+Immediate.h"); } else { imports = FrameworkImport(file_name + ".pbrpc.h", framework) + - FrameworkImport(file_name + ".pbobjc.h", framework); - } - imports += (generator_params.no_v1_compatibility - ? SystemImport("ProtoRPC/ProtoRPC.h") - : SystemImport("ProtoRPC/ProtoRPCLegacy.h")); - if (!generator_params.no_v1_compatibility) { - imports += SystemImport("RxLibrary/GRXWriter+Immediate.h"); + FrameworkImport(file_name + ".pbobjc.h", framework) + + SystemImport("ProtoRPC/ProtoRPC.h") + + SystemImport("RxLibrary/GRXWriter+Immediate.h"); } ::grpc::string class_imports; @@ -223,8 +196,7 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator { ::grpc::string definitions; for (int i = 0; i < file->service_count(); i++) { const grpc::protobuf::ServiceDescriptor* service = file->service(i); - definitions += - grpc_objective_c_generator::GetSource(service, generator_params); + definitions += grpc_objective_c_generator::GetSource(service); } Write(context, file_name + ".pbrpc.m", diff --git a/src/objective-c/BUILD b/src/objective-c/BUILD index 5f53486d17e..3a71086f0f6 100644 --- a/src/objective-c/BUILD +++ b/src/objective-c/BUILD @@ -18,30 +18,24 @@ licenses(["notice"]) # Apache v2 package(default_visibility = ["//visibility:public"]) -load("//bazel:grpc_build_system.bzl", "grpc_objc_library", "grpc_generate_objc_one_off_targets") +load("//bazel:grpc_build_system.bzl", "grpc_objc_library", "grpc_objc_use_cronet_config") exports_files(["LICENSE"]) -grpc_generate_objc_one_off_targets() - -grpc_objc_library( - name = "rx_library_headers", - hdrs = glob([ - "RxLibrary/*.h", - ]), - includes = ["."], -) +grpc_objc_use_cronet_config() grpc_objc_library( name = "rx_library", srcs = glob([ "RxLibrary/*.m", + "RxLibrary/transformations/*.m", + ]), + hdrs = glob([ + "RxLibrary/*.h", + "RxLibrary/transformations/*.h", ]), includes = ["."], - deps = [ - ":rx_library_headers", - ":rx_library_private", - ], + deps = [":rx_library_private"], ) grpc_objc_library( @@ -56,196 +50,84 @@ grpc_objc_library( ) grpc_objc_library( - name = "grpc_objc_interface_legacy", - hdrs = [ - "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "GRPCClient/GRPCCallLegacy.h", - "GRPCClient/GRPCTypes.h", - ], - deps = [ - "rx_library_headers", - ], -) - -grpc_objc_library( - name = "grpc_objc_interface", - hdrs = [ - "GRPCClient/GRPCCall.h", - "GRPCClient/GRPCCall+Interceptor.h", - "GRPCClient/GRPCCallOptions.h", - "GRPCClient/GRPCInterceptor.h", - "GRPCClient/GRPCTransport.h", - "GRPCClient/GRPCDispatchable.h", - "GRPCClient/internal/GRPCCallOptions+Internal.h", - "GRPCClient/version.h", - ], - srcs = [ - "GRPCClient/GRPCCall.m", - "GRPCClient/GRPCCall+Interceptor.m", - "GRPCClient/GRPCCallOptions.m", - "GRPCClient/GRPCInterceptor.m", - "GRPCClient/GRPCTransport.m", - "GRPCClient/private/GRPCTransport+Private.m", - ], - includes = ["."], - textual_hdrs = [ - "GRPCClient/private/GRPCTransport+Private.h", - ], - deps = [ - ":grpc_objc_interface_legacy", - ], -) - -grpc_objc_library( - name = "grpc_objc_client_core", - hdrs = [ - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "GRPCClient/GRPCCall+ChannelArg.h", - ], - textual_hdrs = glob(["GRPCClient/private/GRPCCore/*.h"]), - srcs = [ - "GRPCClient/GRPCCall+ChannelArg.m", - "GRPCClient/GRPCCall+ChannelCredentials.m", - "GRPCClient/GRPCCall+Cronet.m", - "GRPCClient/GRPCCall+OAuth2.m", - "GRPCClient/GRPCCall+Tests.m", - "GRPCClient/GRPCCallLegacy.m", - ] + glob(["GRPCClient/private/GRPCCore/*.m"]), - data = [":gRPCCertificates"], + name = "grpc_objc_client", + srcs = glob( + [ + "GRPCClient/*.m", + "GRPCClient/private/*.m", + ], + exclude = ["GRPCClient/GRPCCall+GID.m"], + ), + hdrs = glob( + [ + "GRPCClient/*.h", + "GRPCClient/internal/*.h", + ], + exclude = ["GRPCClient/GRPCCall+GID.h"], + ), + data = ["//:gRPCCertificates"], includes = ["."], + textual_hdrs = glob([ + "GRPCClient/private/*.h", + ]), deps = [ - ":grpc_objc_interface", - ":grpc_objc_interface_legacy", ":rx_library", "//:grpc_objc", ], ) -alias( - name = "grpc_objc_client", - actual = "grpc_objc_client_core", -) - -grpc_objc_library( - name = "proto_objc_rpc_legacy_header", - hdrs = [ - "ProtoRPC/ProtoRPCLegacy.h", - ], - includes = ["."], -) - -grpc_objc_library( - name = "proto_objc_rpc_v2", - srcs = [ - "ProtoRPC/ProtoMethod.m", - "ProtoRPC/ProtoRPC.m", - "ProtoRPC/ProtoService.m", - ], - hdrs = [ - "ProtoRPC/ProtoMethod.h", - "ProtoRPC/ProtoRPC.h", - "ProtoRPC/ProtoService.h", - ], - includes = ["."], - defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0"], - deps = [ - ":grpc_objc_interface", - ":proto_objc_rpc_legacy_header", - "@com_google_protobuf//:protobuf_objc", - ], -) - grpc_objc_library( name = "proto_objc_rpc", - srcs = [ - "ProtoRPC/ProtoRPCLegacy.m", - "ProtoRPC/ProtoServiceLegacy.m", - ], - hdrs = [ - "ProtoRPC/ProtoMethod.h", - "ProtoRPC/ProtoRPCLegacy.h", - "ProtoRPC/ProtoService.h", - ], + srcs = glob( + ["ProtoRPC/*.m"], + ), + hdrs = glob( + ["ProtoRPC/*.h"], + ), + # Different from Cocoapods, do not import as if @com_google_protobuf//:protobuf_objc is a framework, + # use the real paths of @com_google_protobuf//:protobuf_objc instead + defines = ["GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0"], deps = [ + ":grpc_objc_client", ":rx_library", - ":proto_objc_rpc_v2", - ":proto_objc_rpc_legacy_header", - ":grpc_objc_client_core", "@com_google_protobuf//:protobuf_objc", ], ) -load("@build_bazel_rules_apple//apple:resources.bzl", "apple_resource_bundle") - -apple_resource_bundle( - # The choice of name is signicant here, since it determines the bundle name. - name = "gRPCCertificates", - resources = ["//:etc/roots.pem"], -) - -# Internal target combining grpc_objc_client_core and proto_objc_rpc for testing grpc_objc_library( - name = "grpc_objc_client_core_internal_testing", - hdrs = [ - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/internal_testing/GRPCCall+InternalTests.h", - ], - textual_hdrs = glob(["GRPCClient/private/GRPCCore/*.h"]), - srcs = [ - "GRPCClient/GRPCCall+ChannelArg.m", - "GRPCClient/GRPCCall+ChannelCredentials.m", - "GRPCClient/GRPCCall+Cronet.m", - "GRPCClient/GRPCCall+OAuth2.m", - "GRPCClient/GRPCCall+Tests.m", - "GRPCClient/GRPCCallLegacy.m", - "GRPCClient/internal_testing/GRPCCall+InternalTests.m", - ] + glob(["GRPCClient/private/GRPCCore/*.m"]), - data = [":gRPCCertificates"], + name = "grpc_objc_client_internal_testing", + srcs = glob( + [ + "GRPCClient/*.m", + "GRPCClient/private/*.m", + "GRPCClient/internal_testing/*.m", + "ProtoRPC/*.m", + ], + exclude = ["GRPCClient/GRPCCall+GID.m"], + ), + hdrs = glob( + [ + "GRPCClient/*.h", + "GRPCClient/internal/*.h", + "GRPCClient/internal_testing/*.h", + "ProtoRPC/*.h", + ], + exclude = ["GRPCClient/GRPCCall+GID.h"], + ), includes = ["."], + data = ["//:gRPCCertificates"], defines = [ "GRPC_TEST_OBJC=1", + "GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=0", ], + textual_hdrs = glob( + [ + "GRPCClient/private/*.h", + ], + ), deps = [ - ":grpc_objc_interface", - ":grpc_objc_interface_legacy", ":rx_library", "//:grpc_objc", - ], -) - -grpc_objc_library( - name = "proto_objc_rpc_internal_testing", - srcs = [ - "ProtoRPC/ProtoRPCLegacy.m", - "ProtoRPC/ProtoServiceLegacy.m", - ], - hdrs = [ - "ProtoRPC/ProtoMethod.h", - "ProtoRPC/ProtoRPC.h", - "ProtoRPC/ProtoRPCLegacy.h", - "ProtoRPC/ProtoService.h", - ], - deps = [ - ":rx_library", - ":proto_objc_rpc_v2", - ":proto_objc_rpc_legacy_header", - ":grpc_objc_client_core_internal_testing", "@com_google_protobuf//:protobuf_objc", ], ) - -alias( - name = "grpc_objc_client_internal_testing", - actual = "proto_objc_rpc_internal_testing", -) diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h index ff5a153a0f6..2ddd53a5c66 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.h @@ -15,7 +15,7 @@ * limitations under the License. * */ -#import "GRPCCallLegacy.h" +#import "GRPCCall.h" #include diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m index aae1b740c71..ae60d6208e1 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelArg.m @@ -18,8 +18,8 @@ #import "GRPCCall+ChannelArg.h" -#import "private/GRPCCore/GRPCChannelPool.h" -#import "private/GRPCCore/GRPCHost.h" +#import "private/GRPCChannelPool.h" +#import "private/GRPCHost.h" #import diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h index c3d194bff94..7d6f79b7655 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h @@ -16,7 +16,7 @@ * */ -#import "GRPCCallLegacy.h" +#import "GRPCCall.h" // Deprecated interface. Please use GRPCCallOptions instead. @interface GRPCCall (ChannelCredentials) diff --git a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m index aa97ca82bf8..2689ec2effb 100644 --- a/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m +++ b/src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m @@ -18,7 +18,7 @@ #import "GRPCCall+ChannelCredentials.h" -#import "private/GRPCCore/GRPCHost.h" +#import "private/GRPCHost.h" @implementation GRPCCall (ChannelCredentials) diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.h b/src/objective-c/GRPCClient/GRPCCall+Cronet.h index d107ada3672..3059c6f1860 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.h +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.h @@ -15,16 +15,12 @@ * limitations under the License. * */ +#ifdef GRPC_COMPILE_WITH_CRONET +#import -#import "GRPCCallLegacy.h" -#import "GRPCTypes.h" +#import "GRPCCall.h" -typedef struct stream_engine stream_engine; - -// Transport id for Cronet transport -extern const GRPCTransportId gGRPCCoreCronetId; - -// Deprecated class. Please use the gGRPCCoreCronetId with GRPCCallOptions.transport instead. +// Deprecated interface. Please use GRPCCallOptions instead. @interface GRPCCall (Cronet) + (void)useCronetWithEngine:(stream_engine*)engine; @@ -32,3 +28,4 @@ extern const GRPCTransportId gGRPCCoreCronetId; + (BOOL)isUsingCronet; @end +#endif diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.m b/src/objective-c/GRPCClient/GRPCCall+Cronet.m index a732208e1f6..ba8d2c23db8 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.m +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.m @@ -18,8 +18,7 @@ #import "GRPCCall+Cronet.h" -const GRPCTransportId gGRPCCoreCronetId = "io.grpc.transport.core.cronet"; - +#ifdef GRPC_COMPILE_WITH_CRONET static BOOL useCronet = NO; static stream_engine *globalCronetEngine; @@ -39,3 +38,4 @@ static stream_engine *globalCronetEngine; } @end +#endif diff --git a/src/objective-c/GRPCClient/GRPCCall+GID.h b/src/objective-c/GRPCClient/GRPCCall+GID.h index 80e34ea98da..8293e92ebe9 100644 --- a/src/objective-c/GRPCClient/GRPCCall+GID.h +++ b/src/objective-c/GRPCClient/GRPCCall+GID.h @@ -17,7 +17,7 @@ */ #import "GRPCCall+OAuth2.h" -#import "GRPCCallLegacy.h" +#import "GRPCCall.h" #import diff --git a/src/objective-c/GRPCClient/GRPCCall+OAuth2.h b/src/objective-c/GRPCClient/GRPCCall+OAuth2.h index cf60c794f27..60cdc50bfda 100644 --- a/src/objective-c/GRPCClient/GRPCCall+OAuth2.h +++ b/src/objective-c/GRPCClient/GRPCCall+OAuth2.h @@ -16,9 +16,9 @@ * */ -#import "GRPCCallLegacy.h" +#import "GRPCCall.h" -@protocol GRPCAuthorizationProtocol; +#import "GRPCCallOptions.h" // Deprecated interface. Please use GRPCCallOptions instead. @interface GRPCCall (OAuth2) diff --git a/src/objective-c/GRPCClient/GRPCCall+Tests.h b/src/objective-c/GRPCClient/GRPCCall+Tests.h index af81eec6b82..edaa5ed582c 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Tests.h +++ b/src/objective-c/GRPCClient/GRPCCall+Tests.h @@ -16,7 +16,7 @@ * */ -#import "GRPCCallLegacy.h" +#import "GRPCCall.h" // Deprecated interface. Please use GRPCCallOptions instead. @interface GRPCCall (Tests) diff --git a/src/objective-c/GRPCClient/GRPCCall+Tests.m b/src/objective-c/GRPCClient/GRPCCall+Tests.m index 3a1dff38868..20f5cba4178 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Tests.m +++ b/src/objective-c/GRPCClient/GRPCCall+Tests.m @@ -18,7 +18,7 @@ #import "GRPCCall+Tests.h" -#import "private/GRPCCore/GRPCHost.h" +#import "private/GRPCHost.h" #import "GRPCCallOptions.h" diff --git a/src/objective-c/GRPCClient/GRPCCall.h b/src/objective-c/GRPCClient/GRPCCall.h index 1c7a10048cf..d02ec601727 100644 --- a/src/objective-c/GRPCClient/GRPCCall.h +++ b/src/objective-c/GRPCClient/GRPCCall.h @@ -33,19 +33,134 @@ */ #import +#import -#import "GRPCCallOptions.h" -#import "GRPCDispatchable.h" -#import "GRPCTypes.h" +#include -// The legacy header is included for backwards compatibility. Some V1 API users are still using -// GRPCCall by importing GRPCCall.h header so we need this import. -#import "GRPCCallLegacy.h" +#include "GRPCCallOptions.h" NS_ASSUME_NONNULL_BEGIN +#pragma mark gRPC errors + +/** Domain of NSError objects produced by gRPC. */ +extern NSString *const kGRPCErrorDomain; + +/** + * gRPC error codes. + * Note that a few of these are never produced by the gRPC libraries, but are of general utility for + * server applications to produce. + */ +typedef NS_ENUM(NSUInteger, GRPCErrorCode) { + /** The operation was cancelled (typically by the caller). */ + GRPCErrorCodeCancelled = 1, + + /** + * Unknown error. Errors raised by APIs that do not return enough error information may be + * converted to this error. + */ + GRPCErrorCodeUnknown = 2, + + /** + * The client specified an invalid argument. Note that this differs from FAILED_PRECONDITION. + * INVALID_ARGUMENT indicates arguments that are problematic regardless of the state of the + * server (e.g., a malformed file name). + */ + GRPCErrorCodeInvalidArgument = 3, + + /** + * Deadline expired before operation could complete. For operations that change the state of the + * server, this error may be returned even if the operation has completed successfully. For + * example, a successful response from the server could have been delayed long enough for the + * deadline to expire. + */ + GRPCErrorCodeDeadlineExceeded = 4, + + /** Some requested entity (e.g., file or directory) was not found. */ + GRPCErrorCodeNotFound = 5, + + /** Some entity that we attempted to create (e.g., file or directory) already exists. */ + GRPCErrorCodeAlreadyExists = 6, + + /** + * The caller does not have permission to execute the specified operation. PERMISSION_DENIED isn't + * used for rejections caused by exhausting some resource (RESOURCE_EXHAUSTED is used instead for + * those errors). PERMISSION_DENIED doesn't indicate a failure to identify the caller + * (UNAUTHENTICATED is used instead for those errors). + */ + GRPCErrorCodePermissionDenied = 7, + + /** + * The request does not have valid authentication credentials for the operation (e.g. the caller's + * identity can't be verified). + */ + GRPCErrorCodeUnauthenticated = 16, + + /** Some resource has been exhausted, perhaps a per-user quota. */ + GRPCErrorCodeResourceExhausted = 8, + + /** + * The RPC was rejected because the server is not in a state required for the procedure's + * execution. For example, a directory to be deleted may be non-empty, etc. + * The client should not retry until the server state has been explicitly fixed (e.g. by + * performing another RPC). The details depend on the service being called, and should be found in + * the NSError's userInfo. + */ + GRPCErrorCodeFailedPrecondition = 9, + + /** + * The RPC was aborted, typically due to a concurrency issue like sequencer check failures, + * transaction aborts, etc. The client should retry at a higher-level (e.g., restarting a read- + * modify-write sequence). + */ + GRPCErrorCodeAborted = 10, + + /** + * The RPC was attempted past the valid range. E.g., enumerating past the end of a list. + * Unlike INVALID_ARGUMENT, this error indicates a problem that may be fixed if the system state + * changes. For example, an RPC to get elements of a list will generate INVALID_ARGUMENT if asked + * to return the element at a negative index, but it will generate OUT_OF_RANGE if asked to return + * the element at an index past the current size of the list. + */ + GRPCErrorCodeOutOfRange = 11, + + /** The procedure is not implemented or not supported/enabled in this server. */ + GRPCErrorCodeUnimplemented = 12, + + /** + * Internal error. Means some invariant expected by the server application or the gRPC library has + * been broken. + */ + GRPCErrorCodeInternal = 13, + + /** + * The server is currently unavailable. This is most likely a transient condition and may be + * corrected by retrying with a backoff. Note that it is not always safe to retry + * non-idempotent operations. + */ + GRPCErrorCodeUnavailable = 14, + + /** Unrecoverable data loss or corruption. */ + GRPCErrorCodeDataLoss = 15, +}; + +/** + * Keys used in |NSError|'s |userInfo| dictionary to store the response headers and trailers sent by + * the server. + */ +extern NSString *const kGRPCHeadersKey; +extern NSString *const kGRPCTrailersKey; + /** An object can implement this protocol to receive responses from server from a call. */ -@protocol GRPCResponseHandler +@protocol GRPCResponseHandler + +@required + +/** + * All the responses must be issued to a user-provided dispatch queue. This property specifies the + * dispatch queue to be used for issuing the notifications. + */ +@property(atomic, readonly) dispatch_queue_t dispatchQueue; @optional @@ -187,3 +302,114 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnullability-completeness" + +/** + * This interface is deprecated. Please use \a GRPCcall2. + * + * Represents a single gRPC remote call. + */ +@interface GRPCCall : GRXWriter + +- (instancetype)init NS_UNAVAILABLE; + +/** + * The container of the request headers of an RPC conforms to this protocol, which is a subset of + * NSMutableDictionary's interface. It will become a NSMutableDictionary later on. + * The keys of this container are the header names, which per the HTTP standard are case- + * insensitive. They are stored in lowercase (which is how HTTP/2 mandates them on the wire), and + * can only consist of ASCII characters. + * A header value is a NSString object (with only ASCII characters), unless the header name has the + * suffix "-bin", in which case the value has to be a NSData object. + */ +/** + * These HTTP headers will be passed to the server as part of this call. Each HTTP header is a + * name-value pair with string names and either string or binary values. + * + * The passed dictionary has to use NSString keys, corresponding to the header names. The value + * associated to each can be a NSString object or a NSData object. E.g.: + * + * call.requestHeaders = @{@"authorization": @"Bearer ..."}; + * + * call.requestHeaders[@"my-header-bin"] = someData; + * + * After the call is started, trying to modify this property is an error. + * + * The property is initialized to an empty NSMutableDictionary. + */ +@property(atomic, readonly) NSMutableDictionary *requestHeaders; + +/** + * This dictionary is populated with the HTTP headers received from the server. This happens before + * any response message is received from the server. It has the same structure as the request + * headers dictionary: Keys are NSString header names; names ending with the suffix "-bin" have a + * NSData value; the others have a NSString value. + * + * The value of this property is nil until all response headers are received, and will change before + * any of -writeValue: or -writesFinishedWithError: are sent to the writeable. + */ +@property(atomic, readonly) NSDictionary *responseHeaders; + +/** + * Same as responseHeaders, but populated with the HTTP trailers received from the server before the + * call finishes. + * + * The value of this property is nil until all response trailers are received, and will change + * before -writesFinishedWithError: is sent to the writeable. + */ +@property(atomic, readonly) NSDictionary *responseTrailers; + +/** + * The request writer has to write NSData objects into the provided Writeable. The server will + * receive each of those separately and in order as distinct messages. + * A gRPC call might not complete until the request writer finishes. On the other hand, the request + * finishing doesn't necessarily make the call to finish, as the server might continue sending + * messages to the response side of the call indefinitely (depending on the semantics of the + * specific remote method called). + * To finish a call right away, invoke cancel. + * host parameter should not contain the scheme (http:// or https://), only the name or IP addr + * and the port number, for example @"localhost:5050". + */ +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + requestsWriter:(GRXWriter *)requestWriter; + +/** + * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and + * finishes the response side of the call with an error of code CANCELED. + */ +- (void)cancel; + +/** + * The following methods are deprecated. + */ ++ (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path; +@property(atomic, copy, readwrite) NSString *serverName; +@property NSTimeInterval timeout; +- (void)setResponseDispatchQueue:(dispatch_queue_t)queue; + +@end + +#pragma mark Backwards compatibiity + +/** This protocol is kept for backwards compatibility with existing code. */ +DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") +@protocol GRPCRequestHeaders +@property(nonatomic, readonly) NSUInteger count; + +- (id)objectForKeyedSubscript:(id)key; +- (void)setObject:(id)obj forKeyedSubscript:(id)key; + +- (void)removeAllObjects; +- (void)removeObjectForKey:(id)key; +@end + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated" +/** This is only needed for backwards-compatibility. */ +@interface NSMutableDictionary (GRPCRequestHeaders) +@end +#pragma clang diagnostic pop +#pragma clang diagnostic pop diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m index 73ee530ef2c..cd293cc8e59 100644 --- a/src/objective-c/GRPCClient/GRPCCall.m +++ b/src/objective-c/GRPCClient/GRPCCall.m @@ -17,86 +17,56 @@ */ #import "GRPCCall.h" - #import "GRPCCall+Interceptor.h" +#import "GRPCCall+OAuth2.h" #import "GRPCCallOptions.h" #import "GRPCInterceptor.h" -#import "private/GRPCTransport+Private.h" +#import +#import +#import +#import +#include +#include + +#import "private/GRPCCall+V2API.h" +#import "private/GRPCCallInternal.h" +#import "private/GRPCChannelPool.h" +#import "private/GRPCCompletionQueue.h" +#import "private/GRPCHost.h" +#import "private/GRPCRequestHeaders.h" +#import "private/GRPCWrappedCall.h" +#import "private/NSData+GRPC.h" +#import "private/NSDictionary+GRPC.h" +#import "private/NSError+GRPC.h" + +// At most 6 ops can be in an op batch for a client: SEND_INITIAL_METADATA, +// SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT, RECV_INITIAL_METADATA, RECV_MESSAGE, +// and RECV_STATUS_ON_CLIENT. +NSInteger kMaxClientBatch = 6; NSString *const kGRPCHeadersKey = @"io.grpc.HeadersKey"; NSString *const kGRPCTrailersKey = @"io.grpc.TrailersKey"; +static NSMutableDictionary *callFlags; -NSString *const kGRPCErrorDomain = @"io.grpc"; - -/** - * The response dispatcher creates its own serial dispatch queue and target the queue to the - * dispatch queue of a user provided response handler. It removes the requirement of having to use - * serial dispatch queue in the user provided response handler. - */ -@interface GRPCResponseDispatcher : NSObject - -- (nullable instancetype)initWithResponseHandler:(id)responseHandler; - -@end +static NSString *const kAuthorizationHeader = @"authorization"; +static NSString *const kBearerPrefix = @"Bearer "; -@implementation GRPCResponseDispatcher { - id _responseHandler; - dispatch_queue_t _dispatchQueue; -} +const char *kCFStreamVarName = "grpc_cfstream"; -- (instancetype)initWithResponseHandler:(id)responseHandler { - if ((self = [super init])) { - _responseHandler = responseHandler; -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 - if (@available(iOS 8.0, macOS 10.10, *)) { - _dispatchQueue = dispatch_queue_create( - NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); - } else { -#else - { -#endif - _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - } - dispatch_set_target_queue(_dispatchQueue, _responseHandler.dispatchQueue); - } +@interface GRPCCall () +// Make them read-write. +@property(atomic, strong) NSDictionary *responseHeaders; +@property(atomic, strong) NSDictionary *responseTrailers; - return self; -} - -- (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; -} - -- (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { - if ([_responseHandler respondsToSelector:@selector(didReceiveInitialMetadata:)]) { - [_responseHandler didReceiveInitialMetadata:initialMetadata]; - } -} - -- (void)didReceiveData:(id)data { - // For backwards compatibility with didReceiveRawMessage, if the user provided a response handler - // that handles didReceiveRawMesssage, we issue to that method instead - if ([_responseHandler respondsToSelector:@selector(didReceiveRawMessage:)]) { - [_responseHandler didReceiveRawMessage:data]; - } else if ([_responseHandler respondsToSelector:@selector(didReceiveData:)]) { - [_responseHandler didReceiveData:data]; - } -} - -- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - error:(nullable NSError *)error { - if ([_responseHandler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { - [_responseHandler didCloseWithTrailingMetadata:trailingMetadata error:error]; - } -} +- (void)receiveNextMessages:(NSUInteger)numberOfMessages; -- (void)didWriteData { - if ([_responseHandler respondsToSelector:@selector(didWriteData)]) { - [_responseHandler didWriteData]; - } -} +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + callSafety:(GRPCCallSafety)safety + requestsWriter:(GRXWriter *)requestsWriter + callOptions:(GRPCCallOptions *)callOptions + writeDone:(void (^)(void))writeDone; @end @@ -170,39 +140,54 @@ NSString *const kGRPCErrorDomain = @"io.grpc"; } _responseHandler = responseHandler; - GRPCResponseDispatcher *dispatcher = - [[GRPCResponseDispatcher alloc] initWithResponseHandler:_responseHandler]; - NSMutableArray> *interceptorFactories; - if (_actualCallOptions.interceptorFactories != nil) { - interceptorFactories = - [NSMutableArray arrayWithArray:_actualCallOptions.interceptorFactories]; - } else { - interceptorFactories = [NSMutableArray array]; - } + // Initialize the interceptor chain + + // First initialize the internal call + GRPCCall2Internal *internalCall = [[GRPCCall2Internal alloc] init]; + id nextInterceptor = internalCall; + GRPCInterceptorManager *nextManager = nil; + + // Then initialize the global interceptor, if applicable id globalInterceptorFactory = [GRPCCall2 globalInterceptorFactory]; - if (globalInterceptorFactory != nil) { - [interceptorFactories addObject:globalInterceptorFactory]; + if (globalInterceptorFactory) { + GRPCInterceptorManager *manager = + [[GRPCInterceptorManager alloc] initWithNextInterceptor:nextInterceptor]; + GRPCInterceptor *interceptor = + [globalInterceptorFactory createInterceptorWithManager:manager]; + if (interceptor != nil) { + [internalCall setResponseHandler:interceptor]; + nextInterceptor = interceptor; + nextManager = manager; + } } - // continuously create interceptor until one is successfully created - while (_firstInterceptor == nil) { - if (interceptorFactories.count == 0) { - _firstInterceptor = [[GRPCTransportManager alloc] initWithTransportId:_callOptions.transport - previousInterceptor:dispatcher]; - break; + + // Finally initialize the interceptors in the chain + NSArray *interceptorFactories = _actualCallOptions.interceptorFactories; + for (int i = (int)interceptorFactories.count - 1; i >= 0; i--) { + GRPCInterceptorManager *manager = + [[GRPCInterceptorManager alloc] initWithNextInterceptor:nextInterceptor]; + GRPCInterceptor *interceptor = [interceptorFactories[i] createInterceptorWithManager:manager]; + NSAssert(interceptor != nil, @"Failed to create interceptor from factory: %@", + interceptorFactories[i]); + if (interceptor == nil) { + NSLog(@"Failed to create interceptor from factory: %@", interceptorFactories[i]); + continue; + } + if (nextManager == nil) { + [internalCall setResponseHandler:interceptor]; } else { - _firstInterceptor = - [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories - previousInterceptor:dispatcher - transportId:_callOptions.transport]; - if (_firstInterceptor == nil) { - [interceptorFactories removeObjectAtIndex:0]; - } + [nextManager setPreviousInterceptor:interceptor]; } + nextInterceptor = interceptor; + nextManager = manager; } - NSAssert(_firstInterceptor != nil, @"Failed to create interceptor or transport."); - if (_firstInterceptor == nil) { - NSLog(@"Failed to create interceptor or transport."); + if (nextManager == nil) { + [internalCall setResponseHandler:_responseHandler]; + } else { + [nextManager setPreviousInterceptor:_responseHandler]; } + + _firstInterceptor = nextInterceptor; } return self; @@ -215,42 +200,696 @@ NSString *const kGRPCErrorDomain = @"io.grpc"; } - (void)start { - id copiedFirstInterceptor = _firstInterceptor; - GRPCRequestOptions *requestOptions = _requestOptions; - GRPCCallOptions *callOptions = _actualCallOptions; - dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ - [copiedFirstInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; - }); + id copiedFirstInterceptor; + @synchronized(self) { + copiedFirstInterceptor = _firstInterceptor; + } + GRPCRequestOptions *requestOptions = [_requestOptions copy]; + GRPCCallOptions *callOptions = [_actualCallOptions copy]; + if ([copiedFirstInterceptor respondsToSelector:@selector(startWithRequestOptions:callOptions:)]) { + dispatch_async(copiedFirstInterceptor.requestDispatchQueue, ^{ + [copiedFirstInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; + }); + } } - (void)cancel { - id copiedFirstInterceptor = _firstInterceptor; - if (copiedFirstInterceptor != nil) { - dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ + id copiedFirstInterceptor; + @synchronized(self) { + copiedFirstInterceptor = _firstInterceptor; + } + if ([copiedFirstInterceptor respondsToSelector:@selector(cancel)]) { + dispatch_async(copiedFirstInterceptor.requestDispatchQueue, ^{ [copiedFirstInterceptor cancel]; }); } } - (void)writeData:(id)data { - id copiedFirstInterceptor = _firstInterceptor; - dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ - [copiedFirstInterceptor writeData:data]; - }); + id copiedFirstInterceptor; + @synchronized(self) { + copiedFirstInterceptor = _firstInterceptor; + } + if ([copiedFirstInterceptor respondsToSelector:@selector(writeData:)]) { + dispatch_async(copiedFirstInterceptor.requestDispatchQueue, ^{ + [copiedFirstInterceptor writeData:data]; + }); + } } - (void)finish { - id copiedFirstInterceptor = _firstInterceptor; - dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ - [copiedFirstInterceptor finish]; + id copiedFirstInterceptor; + @synchronized(self) { + copiedFirstInterceptor = _firstInterceptor; + } + if ([copiedFirstInterceptor respondsToSelector:@selector(finish)]) { + dispatch_async(copiedFirstInterceptor.requestDispatchQueue, ^{ + [copiedFirstInterceptor finish]; + }); + } +} + +- (void)receiveNextMessages:(NSUInteger)numberOfMessages { + id copiedFirstInterceptor; + @synchronized(self) { + copiedFirstInterceptor = _firstInterceptor; + } + if ([copiedFirstInterceptor respondsToSelector:@selector(receiveNextMessages:)]) { + dispatch_async(copiedFirstInterceptor.requestDispatchQueue, ^{ + [copiedFirstInterceptor receiveNextMessages:numberOfMessages]; + }); + } +} + +@end + +// The following methods of a C gRPC call object aren't reentrant, and thus +// calls to them must be serialized: +// - start_batch +// - destroy +// +// start_batch with a SEND_MESSAGE argument can only be called after the +// OP_COMPLETE event for any previous write is received. This is achieved by +// pausing the requests writer immediately every time it writes a value, and +// resuming it again when OP_COMPLETE is received. +// +// Similarly, start_batch with a RECV_MESSAGE argument can only be called after +// the OP_COMPLETE event for any previous read is received.This is easier to +// enforce, as we're writing the received messages into the writeable: +// start_batch is enqueued once upon receiving the OP_COMPLETE event for the +// RECV_METADATA batch, and then once after receiving each OP_COMPLETE event for +// each RECV_MESSAGE batch. +@implementation GRPCCall { + dispatch_queue_t _callQueue; + + NSString *_host; + NSString *_path; + GRPCCallSafety _callSafety; + GRPCCallOptions *_callOptions; + GRPCWrappedCall *_wrappedCall; + + // The C gRPC library has less guarantees on the ordering of events than we + // do. Particularly, in the face of errors, there's no ordering guarantee at + // all. This wrapper over our actual writeable ensures thread-safety and + // correct ordering. + GRXConcurrentWriteable *_responseWriteable; + + // The network thread wants the requestWriter to resume (when the server is ready for more input), + // or to stop (on errors), concurrently with user threads that want to start it, pause it or stop + // it. Because a writer isn't thread-safe, we'll synchronize those operations on it. + // We don't use a dispatch queue for that purpose, because the writer can call writeValue: or + // writesFinishedWithError: on this GRPCCall as part of those operations. We want to be able to + // pause the writer immediately on writeValue:, so we need our locking to be recursive. + GRXWriter *_requestWriter; + + // To create a retain cycle when a call is started, up until it finishes. See + // |startWithWriteable:| and |finishWithError:|. This saves users from having to retain a + // reference to the call object if all they're interested in is the handler being executed when + // the response arrives. + GRPCCall *_retainSelf; + + GRPCRequestHeaders *_requestHeaders; + + // In the case that the call is a unary call (i.e. the writer to GRPCCall is of type + // GRXImmediateSingleWriter), GRPCCall will delay sending ops (not send them to C core + // immediately) and buffer them into a batch _unaryOpBatch. The batch is sent to C core when + // the SendClose op is added. + BOOL _unaryCall; + NSMutableArray *_unaryOpBatch; + + // The dispatch queue to be used for enqueuing responses to user. Defaulted to the main dispatch + // queue + dispatch_queue_t _responseQueue; + + // The OAuth2 token fetched from a token provider. + NSString *_fetchedOauth2AccessToken; + + // The callback to be called when a write message op is done. + void (^_writeDone)(void); + + // Indicate a read request to core is pending. + BOOL _pendingCoreRead; + + // Indicate pending read message request from user. + NSUInteger _pendingReceiveNextMessages; +} + +@synthesize state = _state; + ++ (void)initialize { + // Guarantees the code in {} block is invoked only once. See ref at: + // https://developer.apple.com/documentation/objectivec/nsobject/1418639-initialize?language=objc + if (self == [GRPCCall self]) { + grpc_init(); + callFlags = [NSMutableDictionary dictionary]; + } +} + ++ (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path { + if (host.length == 0 || path.length == 0) { + return; + } + NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; + @synchronized(callFlags) { + switch (callSafety) { + case GRPCCallSafetyDefault: + callFlags[hostAndPath] = @0; + break; + case GRPCCallSafetyIdempotentRequest: + callFlags[hostAndPath] = @GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST; + break; + case GRPCCallSafetyCacheableRequest: + callFlags[hostAndPath] = @GRPC_INITIAL_METADATA_CACHEABLE_REQUEST; + break; + default: + break; + } + } +} + ++ (uint32_t)callFlagsForHost:(NSString *)host path:(NSString *)path { + NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; + @synchronized(callFlags) { + return [callFlags[hostAndPath] intValue]; + } +} + +// Designated initializer +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + requestsWriter:(GRXWriter *)requestWriter { + return [self initWithHost:host + path:path + callSafety:GRPCCallSafetyDefault + requestsWriter:requestWriter + callOptions:nil]; +} + +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + callSafety:(GRPCCallSafety)safety + requestsWriter:(GRXWriter *)requestsWriter + callOptions:(GRPCCallOptions *)callOptions { + return [self initWithHost:host + path:path + callSafety:safety + requestsWriter:requestsWriter + callOptions:callOptions + writeDone:nil]; +} + +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + callSafety:(GRPCCallSafety)safety + requestsWriter:(GRXWriter *)requestsWriter + callOptions:(GRPCCallOptions *)callOptions + writeDone:(void (^)(void))writeDone { + // Purposely using pointer rather than length (host.length == 0) for backwards compatibility. + NSAssert(host != nil && path != nil, @"Neither host nor path can be nil."); + NSAssert(safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value."); + NSAssert(requestsWriter.state == GRXWriterStateNotStarted, + @"The requests writer can't be already started."); + if (!host || !path) { + return nil; + } + if (safety > GRPCCallSafetyCacheableRequest) { + return nil; + } + if (requestsWriter.state != GRXWriterStateNotStarted) { + return nil; + } + + if ((self = [super init])) { + _host = [host copy]; + _path = [path copy]; + _callSafety = safety; + _callOptions = [callOptions copy]; + + // Serial queue to invoke the non-reentrant methods of the grpc_call object. + _callQueue = dispatch_queue_create("io.grpc.call", DISPATCH_QUEUE_SERIAL); + + _requestWriter = requestsWriter; + _requestHeaders = [[GRPCRequestHeaders alloc] initWithCall:self]; + _writeDone = writeDone; + + if ([requestsWriter isKindOfClass:[GRXImmediateSingleWriter class]]) { + _unaryCall = YES; + _unaryOpBatch = [NSMutableArray arrayWithCapacity:kMaxClientBatch]; + } + + _responseQueue = dispatch_get_main_queue(); + + // do not start a read until initial metadata is received + _pendingReceiveNextMessages = 0; + _pendingCoreRead = YES; + } + return self; +} + +- (void)setResponseDispatchQueue:(dispatch_queue_t)queue { + @synchronized(self) { + if (_state != GRXWriterStateNotStarted) { + return; + } + _responseQueue = queue; + } +} + +#pragma mark Finish + +// This function should support being called within a @synchronized(self) block in another function +// Should not manipulate _requestWriter for deadlock prevention. +- (void)finishWithError:(NSError *)errorOrNil { + @synchronized(self) { + if (_state == GRXWriterStateFinished) { + return; + } + _state = GRXWriterStateFinished; + + if (errorOrNil) { + [_responseWriteable cancelWithError:errorOrNil]; + } else { + [_responseWriteable enqueueSuccessfulCompletion]; + } + + // If the call isn't retained anywhere else, it can be deallocated now. + _retainSelf = nil; + } +} + +- (void)cancel { + @synchronized(self) { + if (_state == GRXWriterStateFinished) { + return; + } + [self finishWithError:[NSError + errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeCancelled + userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]]; + [_wrappedCall cancel]; + } + _requestWriter.state = GRXWriterStateFinished; +} + +- (void)dealloc { + __block GRPCWrappedCall *wrappedCall = _wrappedCall; + dispatch_async(_callQueue, ^{ + wrappedCall = nil; + }); +} + +#pragma mark Read messages + +// Only called from the call queue. +// The handler will be called from the network queue. +- (void)startReadWithHandler:(void (^)(grpc_byte_buffer *))handler { + // TODO(jcanizales): Add error handlers for async failures + [_wrappedCall startBatchWithOperations:@[ [[GRPCOpRecvMessage alloc] initWithHandler:handler] ]]; +} + +// Called initially from the network queue once response headers are received, +// then "recursively" from the responseWriteable queue after each response from the +// server has been written. +// If the call is currently paused, this is a noop. Restarting the call will invoke this +// method. +// TODO(jcanizales): Rename to readResponseIfNotPaused. +- (void)maybeStartNextRead { + @synchronized(self) { + if (_state != GRXWriterStateStarted) { + return; + } + if (_callOptions.flowControlEnabled && (_pendingCoreRead || _pendingReceiveNextMessages == 0)) { + return; + } + _pendingCoreRead = YES; + _pendingReceiveNextMessages--; + } + + dispatch_async(_callQueue, ^{ + __weak GRPCCall *weakSelf = self; + [self startReadWithHandler:^(grpc_byte_buffer *message) { + if (message == NULL) { + // No more messages from the server + return; + } + __strong GRPCCall *strongSelf = weakSelf; + if (strongSelf == nil) { + grpc_byte_buffer_destroy(message); + return; + } + NSData *data = [NSData grpc_dataWithByteBuffer:message]; + grpc_byte_buffer_destroy(message); + if (!data) { + // The app doesn't have enough memory to hold the server response. We + // don't want to throw, because the app shouldn't crash for a behavior + // that's on the hands of any server to have. Instead we finish and ask + // the server to cancel. + @synchronized(strongSelf) { + strongSelf->_pendingCoreRead = NO; + [strongSelf + finishWithError:[NSError errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeResourceExhausted + userInfo:@{ + NSLocalizedDescriptionKey : + @"Client does not have enough memory to " + @"hold the server response." + }]]; + [strongSelf->_wrappedCall cancel]; + } + strongSelf->_requestWriter.state = GRXWriterStateFinished; + } else { + @synchronized(strongSelf) { + [strongSelf->_responseWriteable enqueueValue:data + completionHandler:^{ + __strong GRPCCall *strongSelf = weakSelf; + if (strongSelf) { + @synchronized(strongSelf) { + strongSelf->_pendingCoreRead = NO; + [strongSelf maybeStartNextRead]; + } + } + }]; + } + } + }]; + }); +} + +#pragma mark Send headers + +- (void)sendHeaders { + // TODO (mxyan): Remove after deprecated methods are removed + uint32_t callSafetyFlags = 0; + switch (_callSafety) { + case GRPCCallSafetyDefault: + callSafetyFlags = 0; + break; + case GRPCCallSafetyIdempotentRequest: + callSafetyFlags = GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST; + break; + case GRPCCallSafetyCacheableRequest: + callSafetyFlags = GRPC_INITIAL_METADATA_CACHEABLE_REQUEST; + break; + } + + NSMutableDictionary *headers = [_requestHeaders mutableCopy]; + NSString *fetchedOauth2AccessToken; + @synchronized(self) { + fetchedOauth2AccessToken = _fetchedOauth2AccessToken; + } + if (fetchedOauth2AccessToken != nil) { + headers[@"authorization"] = [kBearerPrefix stringByAppendingString:fetchedOauth2AccessToken]; + } else if (_callOptions.oauth2AccessToken != nil) { + headers[@"authorization"] = + [kBearerPrefix stringByAppendingString:_callOptions.oauth2AccessToken]; + } + + // TODO(jcanizales): Add error handlers for async failures + GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc] + initWithMetadata:headers + flags:callSafetyFlags + handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA + dispatch_async(_callQueue, ^{ + if (!self->_unaryCall) { + [self->_wrappedCall startBatchWithOperations:@[ op ]]; + } else { + [self->_unaryOpBatch addObject:op]; + } }); } - (void)receiveNextMessages:(NSUInteger)numberOfMessages { - id copiedFirstInterceptor = _firstInterceptor; - dispatch_async(copiedFirstInterceptor.dispatchQueue, ^{ - [copiedFirstInterceptor receiveNextMessages:numberOfMessages]; + if (numberOfMessages == 0) { + return; + } + @synchronized(self) { + _pendingReceiveNextMessages += numberOfMessages; + + if (_state != GRXWriterStateStarted || !_callOptions.flowControlEnabled) { + return; + } + [self maybeStartNextRead]; + } +} + +#pragma mark GRXWriteable implementation + +// Only called from the call queue. The error handler will be called from the +// network queue if the write didn't succeed. +// If the call is a unary call, parameter \a errorHandler will be ignored and +// the error handler of GRPCOpSendClose will be executed in case of error. +- (void)writeMessage:(NSData *)message withErrorHandler:(void (^)(void))errorHandler { + __weak GRPCCall *weakSelf = self; + void (^resumingHandler)(void) = ^{ + // Resume the request writer. + GRPCCall *strongSelf = weakSelf; + if (strongSelf) { + strongSelf->_requestWriter.state = GRXWriterStateStarted; + if (strongSelf->_writeDone) { + strongSelf->_writeDone(); + } + } + }; + GRPCOpSendMessage *op = + [[GRPCOpSendMessage alloc] initWithMessage:message handler:resumingHandler]; + if (!_unaryCall) { + [_wrappedCall startBatchWithOperations:@[ op ] errorHandler:errorHandler]; + } else { + // Ignored errorHandler since it is the same as the one for GRPCOpSendClose. + // TODO (mxyan): unify the error handlers of all Ops into a single closure. + [_unaryOpBatch addObject:op]; + } +} + +- (void)writeValue:(id)value { + NSAssert([value isKindOfClass:[NSData class]], @"value must be of type NSData"); + + @synchronized(self) { + if (_state == GRXWriterStateFinished) { + return; + } + } + + // Pause the input and only resume it when the C layer notifies us that writes + // can proceed. + _requestWriter.state = GRXWriterStatePaused; + + dispatch_async(_callQueue, ^{ + // Write error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT + [self writeMessage:value withErrorHandler:nil]; + }); +} + +// Only called from the call queue. The error handler will be called from the +// network queue if the requests stream couldn't be closed successfully. +- (void)finishRequestWithErrorHandler:(void (^)(void))errorHandler { + if (!_unaryCall) { + [_wrappedCall startBatchWithOperations:@[ [[GRPCOpSendClose alloc] init] ] + errorHandler:errorHandler]; + } else { + [_unaryOpBatch addObject:[[GRPCOpSendClose alloc] init]]; + [_wrappedCall startBatchWithOperations:_unaryOpBatch errorHandler:errorHandler]; + } +} + +- (void)writesFinishedWithError:(NSError *)errorOrNil { + if (errorOrNil) { + [self cancel]; + } else { + dispatch_async(_callQueue, ^{ + // EOS error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT + [self finishRequestWithErrorHandler:nil]; + }); + } +} + +#pragma mark Invoke + +// Both handlers will eventually be called, from the network queue. Writes can start immediately +// after this. +// The first one (headersHandler), when the response headers are received. +// The second one (completionHandler), whenever the RPC finishes for any reason. +- (void)invokeCallWithHeadersHandler:(void (^)(NSDictionary *))headersHandler + completionHandler:(void (^)(NSError *, NSDictionary *))completionHandler { + dispatch_async(_callQueue, ^{ + // TODO(jcanizales): Add error handlers for async failures + [self->_wrappedCall + startBatchWithOperations:@[ [[GRPCOpRecvMetadata alloc] initWithHandler:headersHandler] ]]; + [self->_wrappedCall + startBatchWithOperations:@[ [[GRPCOpRecvStatus alloc] initWithHandler:completionHandler] ]]; }); } +- (void)invokeCall { + __weak GRPCCall *weakSelf = self; + [self invokeCallWithHeadersHandler:^(NSDictionary *headers) { + // Response headers received. + __strong GRPCCall *strongSelf = weakSelf; + if (strongSelf) { + @synchronized(strongSelf) { + // it is ok to set nil because headers are only received once + strongSelf.responseHeaders = nil; + // copy the header so that the GRPCOpRecvMetadata object may be dealloc'ed + NSDictionary *copiedHeaders = + [[NSDictionary alloc] initWithDictionary:headers copyItems:YES]; + strongSelf.responseHeaders = copiedHeaders; + strongSelf->_pendingCoreRead = NO; + [strongSelf maybeStartNextRead]; + } + } + } + completionHandler:^(NSError *error, NSDictionary *trailers) { + __strong GRPCCall *strongSelf = weakSelf; + if (strongSelf) { + strongSelf.responseTrailers = trailers; + + if (error) { + NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; + if (error.userInfo) { + [userInfo addEntriesFromDictionary:error.userInfo]; + } + userInfo[kGRPCTrailersKey] = strongSelf.responseTrailers; + // Since gRPC core does not guarantee the headers block being called before this block, + // responseHeaders might be nil. + userInfo[kGRPCHeadersKey] = strongSelf.responseHeaders; + error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; + } + [strongSelf finishWithError:error]; + strongSelf->_requestWriter.state = GRXWriterStateFinished; + } + }]; +} + +#pragma mark GRXWriter implementation + +// Lock acquired inside startWithWriteable: +- (void)startCallWithWriteable:(id)writeable { + @synchronized(self) { + if (_state == GRXWriterStateFinished) { + return; + } + + _responseWriteable = + [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; + + GRPCPooledChannel *channel = + [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; + _wrappedCall = [channel wrappedCallWithPath:_path + completionQueue:[GRPCCompletionQueue completionQueue] + callOptions:_callOptions]; + + if (_wrappedCall == nil) { + [self finishWithError:[NSError errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeUnavailable + userInfo:@{ + NSLocalizedDescriptionKey : + @"Failed to create call or channel." + }]]; + return; + } + + [self sendHeaders]; + [self invokeCall]; + } + + // Now that the RPC has been initiated, request writes can start. + [_requestWriter startWithWriteable:self]; +} + +- (void)startWithWriteable:(id)writeable { + id tokenProvider = nil; + @synchronized(self) { + _state = GRXWriterStateStarted; + + // Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled). + // This makes RPCs in which the call isn't externally retained possible (as long as it is + // started before being autoreleased). Care is taken not to retain self strongly in any of the + // blocks used in this implementation, so that the life of the instance is determined by this + // retain cycle. + _retainSelf = self; + + if (_callOptions == nil) { + GRPCMutableCallOptions *callOptions = [[GRPCHost callOptionsForHost:_host] mutableCopy]; + if (_serverName.length != 0) { + callOptions.serverAuthority = _serverName; + } + if (_timeout > 0) { + callOptions.timeout = _timeout; + } + uint32_t callFlags = [GRPCCall callFlagsForHost:_host path:_path]; + if (callFlags != 0) { + if (callFlags == GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) { + _callSafety = GRPCCallSafetyIdempotentRequest; + } else if (callFlags == GRPC_INITIAL_METADATA_CACHEABLE_REQUEST) { + _callSafety = GRPCCallSafetyCacheableRequest; + } + } + + id tokenProvider = self.tokenProvider; + if (tokenProvider != nil) { + callOptions.authTokenProvider = tokenProvider; + } + _callOptions = callOptions; + } + + NSAssert(_callOptions.authTokenProvider == nil || _callOptions.oauth2AccessToken == nil, + @"authTokenProvider and oauth2AccessToken cannot be set at the same time"); + + tokenProvider = _callOptions.authTokenProvider; + } + + if (tokenProvider != nil) { + __weak typeof(self) weakSelf = self; + [tokenProvider getTokenWithHandler:^(NSString *token) { + __strong typeof(self) strongSelf = weakSelf; + if (strongSelf) { + BOOL startCall = NO; + @synchronized(strongSelf) { + if (strongSelf->_state != GRXWriterStateFinished) { + startCall = YES; + if (token) { + strongSelf->_fetchedOauth2AccessToken = [token copy]; + } + } + } + if (startCall) { + [strongSelf startCallWithWriteable:writeable]; + } + } + }]; + } else { + [self startCallWithWriteable:writeable]; + } +} + +- (void)setState:(GRXWriterState)newState { + @synchronized(self) { + // Manual transitions are only allowed from the started or paused states. + if (_state == GRXWriterStateNotStarted || _state == GRXWriterStateFinished) { + return; + } + + switch (newState) { + case GRXWriterStateFinished: + _state = newState; + // Per GRXWriter's contract, setting the state to Finished manually + // means one doesn't wish the writeable to be messaged anymore. + [_responseWriteable cancelSilently]; + _responseWriteable = nil; + return; + case GRXWriterStatePaused: + _state = newState; + return; + case GRXWriterStateStarted: + if (_state == GRXWriterStatePaused) { + _state = newState; + [self maybeStartNextRead]; + } + return; + case GRXWriterStateNotStarted: + return; + } + } +} + @end diff --git a/src/objective-c/GRPCClient/GRPCCallLegacy.h b/src/objective-c/GRPCClient/GRPCCallLegacy.h deleted file mode 100644 index 51dd7da3440..00000000000 --- a/src/objective-c/GRPCClient/GRPCCallLegacy.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * This is the legacy interface of this gRPC library. This API is deprecated and users should use - * the API in GRPCCall.h. This API exists solely for the purpose of backwards compatibility. - */ - -#import -#import "GRPCTypes.h" - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnullability-completeness" - -/** - * This interface is deprecated. Please use \a GRPCCall2. - * - * Represents a single gRPC remote call. - */ -@interface GRPCCall : GRXWriter - -- (instancetype)init NS_UNAVAILABLE; - -/** - * The container of the request headers of an RPC conforms to this protocol, which is a subset of - * NSMutableDictionary's interface. It will become a NSMutableDictionary later on. - * The keys of this container are the header names, which per the HTTP standard are case- - * insensitive. They are stored in lowercase (which is how HTTP/2 mandates them on the wire), and - * can only consist of ASCII characters. - * A header value is a NSString object (with only ASCII characters), unless the header name has the - * suffix "-bin", in which case the value has to be a NSData object. - */ -/** - * These HTTP headers will be passed to the server as part of this call. Each HTTP header is a - * name-value pair with string names and either string or binary values. - * - * The passed dictionary has to use NSString keys, corresponding to the header names. The value - * associated to each can be a NSString object or a NSData object. E.g.: - * - * call.requestHeaders = @{@"authorization": @"Bearer ..."}; - * - * call.requestHeaders[@"my-header-bin"] = someData; - * - * After the call is started, trying to modify this property is an error. - * - * The property is initialized to an empty NSMutableDictionary. - */ -@property(atomic, readonly) NSMutableDictionary *requestHeaders; - -/** - * This dictionary is populated with the HTTP headers received from the server. This happens before - * any response message is received from the server. It has the same structure as the request - * headers dictionary: Keys are NSString header names; names ending with the suffix "-bin" have a - * NSData value; the others have a NSString value. - * - * The value of this property is nil until all response headers are received, and will change before - * any of -writeValue: or -writesFinishedWithError: are sent to the writeable. - */ -@property(atomic, readonly) NSDictionary *responseHeaders; - -/** - * Same as responseHeaders, but populated with the HTTP trailers received from the server before the - * call finishes. - * - * The value of this property is nil until all response trailers are received, and will change - * before -writesFinishedWithError: is sent to the writeable. - */ -@property(atomic, readonly) NSDictionary *responseTrailers; - -/** - * The request writer has to write NSData objects into the provided Writeable. The server will - * receive each of those separately and in order as distinct messages. - * A gRPC call might not complete until the request writer finishes. On the other hand, the request - * finishing doesn't necessarily make the call to finish, as the server might continue sending - * messages to the response side of the call indefinitely (depending on the semantics of the - * specific remote method called). - * To finish a call right away, invoke cancel. - * host parameter should not contain the scheme (http:// or https://), only the name or IP addr - * and the port number, for example @"localhost:5050". - */ -- (instancetype)initWithHost:(NSString *)host - path:(NSString *)path - requestsWriter:(GRXWriter *)requestWriter; - -/** - * Finishes the request side of this call, notifies the server that the RPC should be cancelled, and - * finishes the response side of the call with an error of code CANCELED. - */ -- (void)cancel; - -/** - * The following methods are deprecated. - */ -+ (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path; -@property(atomic, copy, readwrite) NSString *serverName; -@property NSTimeInterval timeout; -- (void)setResponseDispatchQueue:(dispatch_queue_t)queue; - -@end - -#pragma mark Backwards compatibiity - -/** This protocol is kept for backwards compatibility with existing code. */ -DEPRECATED_MSG_ATTRIBUTE("Use NSDictionary or NSMutableDictionary instead.") -@protocol GRPCRequestHeaders -@property(nonatomic, readonly) NSUInteger count; - -- (id)objectForKeyedSubscript:(id)key; -- (void)setObject:(id)obj forKeyedSubscript:(id)key; - -- (void)removeAllObjects; -- (void)removeObjectForKey:(id)key; -@end - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated" -/** This is only needed for backwards-compatibility. */ -@interface NSMutableDictionary (GRPCRequestHeaders) -@end -#pragma clang diagnostic pop -#pragma clang diagnostic pop diff --git a/src/objective-c/GRPCClient/GRPCCallLegacy.m b/src/objective-c/GRPCClient/GRPCCallLegacy.m deleted file mode 100644 index d06048c3a89..00000000000 --- a/src/objective-c/GRPCClient/GRPCCallLegacy.m +++ /dev/null @@ -1,677 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "GRPCCallLegacy.h" - -#import "GRPCCall+OAuth2.h" -#import "GRPCCallOptions.h" -#import "GRPCTypes.h" - -#import "private/GRPCCore/GRPCChannelPool.h" -#import "private/GRPCCore/GRPCCompletionQueue.h" -#import "private/GRPCCore/GRPCHost.h" -#import "private/GRPCCore/GRPCWrappedCall.h" -#import "private/GRPCCore/NSData+GRPC.h" - -#import -#import -#import -#import - -#include - -const char *kCFStreamVarName = "grpc_cfstream"; -static NSMutableDictionary *callFlags; - -// At most 6 ops can be in an op batch for a client: SEND_INITIAL_METADATA, -// SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT, RECV_INITIAL_METADATA, RECV_MESSAGE, -// and RECV_STATUS_ON_CLIENT. -NSInteger kMaxClientBatch = 6; - -static NSString *const kAuthorizationHeader = @"authorization"; -static NSString *const kBearerPrefix = @"Bearer "; - -@interface GRPCCall () -// Make them read-write. -@property(atomic, strong) NSDictionary *responseHeaders; -@property(atomic, strong) NSDictionary *responseTrailers; - -- (void)receiveNextMessages:(NSUInteger)numberOfMessages; - -@end - -// The following methods of a C gRPC call object aren't reentrant, and thus -// calls to them must be serialized: -// - start_batch -// - destroy -// -// start_batch with a SEND_MESSAGE argument can only be called after the -// OP_COMPLETE event for any previous write is received. This is achieved by -// pausing the requests writer immediately every time it writes a value, and -// resuming it again when OP_COMPLETE is received. -// -// Similarly, start_batch with a RECV_MESSAGE argument can only be called after -// the OP_COMPLETE event for any previous read is received.This is easier to -// enforce, as we're writing the received messages into the writeable: -// start_batch is enqueued once upon receiving the OP_COMPLETE event for the -// RECV_METADATA batch, and then once after receiving each OP_COMPLETE event for -// each RECV_MESSAGE batch. -@implementation GRPCCall { - dispatch_queue_t _callQueue; - - NSString *_host; - NSString *_path; - GRPCCallSafety _callSafety; - GRPCCallOptions *_callOptions; - GRPCWrappedCall *_wrappedCall; - - // The C gRPC library has less guarantees on the ordering of events than we - // do. Particularly, in the face of errors, there's no ordering guarantee at - // all. This wrapper over our actual writeable ensures thread-safety and - // correct ordering. - GRXConcurrentWriteable *_responseWriteable; - - // The network thread wants the requestWriter to resume (when the server is ready for more input), - // or to stop (on errors), concurrently with user threads that want to start it, pause it or stop - // it. Because a writer isn't thread-safe, we'll synchronize those operations on it. - // We don't use a dispatch queue for that purpose, because the writer can call writeValue: or - // writesFinishedWithError: on this GRPCCall as part of those operations. We want to be able to - // pause the writer immediately on writeValue:, so we need our locking to be recursive. - GRXWriter *_requestWriter; - - // To create a retain cycle when a call is started, up until it finishes. See - // |startWithWriteable:| and |finishWithError:|. This saves users from having to retain a - // reference to the call object if all they're interested in is the handler being executed when - // the response arrives. - GRPCCall *_retainSelf; - - GRPCRequestHeaders *_requestHeaders; - - // In the case that the call is a unary call (i.e. the writer to GRPCCall is of type - // GRXImmediateSingleWriter), GRPCCall will delay sending ops (not send them to C core - // immediately) and buffer them into a batch _unaryOpBatch. The batch is sent to C core when - // the SendClose op is added. - BOOL _unaryCall; - NSMutableArray *_unaryOpBatch; - - // The dispatch queue to be used for enqueuing responses to user. Defaulted to the main dispatch - // queue - dispatch_queue_t _responseQueue; - - // The OAuth2 token fetched from a token provider. - NSString *_fetchedOauth2AccessToken; - - // The callback to be called when a write message op is done. - void (^_writeDone)(void); - - // Indicate a read request to core is pending. - BOOL _pendingCoreRead; - - // Indicate pending read message request from user. - NSUInteger _pendingReceiveNextMessages; -} - -@synthesize state = _state; - -+ (void)initialize { - // Guarantees the code in {} block is invoked only once. See ref at: - // https://developer.apple.com/documentation/objectivec/nsobject/1418639-initialize?language=objc - if (self == [GRPCCall self]) { - grpc_init(); - callFlags = [NSMutableDictionary dictionary]; - } -} - -+ (void)setCallSafety:(GRPCCallSafety)callSafety host:(NSString *)host path:(NSString *)path { - if (host.length == 0 || path.length == 0) { - return; - } - NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; - @synchronized(callFlags) { - switch (callSafety) { - case GRPCCallSafetyDefault: - callFlags[hostAndPath] = @0; - break; - case GRPCCallSafetyIdempotentRequest: - callFlags[hostAndPath] = @GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST; - break; - case GRPCCallSafetyCacheableRequest: - callFlags[hostAndPath] = @GRPC_INITIAL_METADATA_CACHEABLE_REQUEST; - break; - default: - break; - } - } -} - -+ (uint32_t)callFlagsForHost:(NSString *)host path:(NSString *)path { - NSString *hostAndPath = [NSString stringWithFormat:@"%@/%@", host, path]; - @synchronized(callFlags) { - return [callFlags[hostAndPath] intValue]; - } -} - -- (instancetype)initWithHost:(NSString *)host - path:(NSString *)path - requestsWriter:(GRXWriter *)requestWriter { - return [self initWithHost:host - path:path - callSafety:GRPCCallSafetyDefault - requestsWriter:requestWriter - callOptions:nil - writeDone:nil]; -} - -- (instancetype)initWithHost:(NSString *)host - path:(NSString *)path - callSafety:(GRPCCallSafety)safety - requestsWriter:(GRXWriter *)requestsWriter - callOptions:(GRPCCallOptions *)callOptions - writeDone:(void (^)(void))writeDone { - // Purposely using pointer rather than length (host.length == 0) for backwards compatibility. - NSAssert(host != nil && path != nil, @"Neither host nor path can be nil."); - NSAssert(safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value."); - NSAssert(requestsWriter.state == GRXWriterStateNotStarted, - @"The requests writer can't be already started."); - if (!host || !path) { - return nil; - } - if (safety > GRPCCallSafetyCacheableRequest) { - return nil; - } - if (requestsWriter.state != GRXWriterStateNotStarted) { - return nil; - } - - if ((self = [super init])) { - _host = [host copy]; - _path = [path copy]; - _callSafety = safety; - _callOptions = [callOptions copy]; - - // Serial queue to invoke the non-reentrant methods of the grpc_call object. - _callQueue = dispatch_queue_create("io.grpc.call", DISPATCH_QUEUE_SERIAL); - - _requestWriter = requestsWriter; - _requestHeaders = [[GRPCRequestHeaders alloc] initWithCall:self]; - _writeDone = writeDone; - - if ([requestsWriter isKindOfClass:[GRXImmediateSingleWriter class]]) { - _unaryCall = YES; - _unaryOpBatch = [NSMutableArray arrayWithCapacity:kMaxClientBatch]; - } - - _responseQueue = dispatch_get_main_queue(); - - // do not start a read until initial metadata is received - _pendingReceiveNextMessages = 0; - _pendingCoreRead = YES; - } - return self; -} - -- (void)setResponseDispatchQueue:(dispatch_queue_t)queue { - @synchronized(self) { - if (_state != GRXWriterStateNotStarted) { - return; - } - _responseQueue = queue; - } -} - -#pragma mark Finish - -// This function should support being called within a @synchronized(self) block in another function -// Should not manipulate _requestWriter for deadlock prevention. -- (void)finishWithError:(NSError *)errorOrNil { - @synchronized(self) { - if (_state == GRXWriterStateFinished) { - return; - } - _state = GRXWriterStateFinished; - - if (errorOrNil) { - [_responseWriteable cancelWithError:errorOrNil]; - } else { - [_responseWriteable enqueueSuccessfulCompletion]; - } - - // If the call isn't retained anywhere else, it can be deallocated now. - _retainSelf = nil; - } -} - -- (void)cancel { - @synchronized(self) { - if (_state == GRXWriterStateFinished) { - return; - } - [self finishWithError:[NSError - errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeCancelled - userInfo:@{NSLocalizedDescriptionKey : @"Canceled by app"}]]; - [_wrappedCall cancel]; - } - _requestWriter.state = GRXWriterStateFinished; -} - -- (void)dealloc { - __block GRPCWrappedCall *wrappedCall = _wrappedCall; - dispatch_async(_callQueue, ^{ - wrappedCall = nil; - }); -} - -#pragma mark Read messages - -// Only called from the call queue. -// The handler will be called from the network queue. -- (void)startReadWithHandler:(void (^)(grpc_byte_buffer *))handler { - // TODO(jcanizales): Add error handlers for async failures - [_wrappedCall startBatchWithOperations:@[ [[GRPCOpRecvMessage alloc] initWithHandler:handler] ]]; -} - -// Called initially from the network queue once response headers are received, -// then "recursively" from the responseWriteable queue after each response from the -// server has been written. -// If the call is currently paused, this is a noop. Restarting the call will invoke this -// method. -// TODO(jcanizales): Rename to readResponseIfNotPaused. -- (void)maybeStartNextRead { - @synchronized(self) { - if (_state != GRXWriterStateStarted) { - return; - } - if (_callOptions.flowControlEnabled && (_pendingCoreRead || _pendingReceiveNextMessages == 0)) { - return; - } - _pendingCoreRead = YES; - _pendingReceiveNextMessages--; - } - - dispatch_async(_callQueue, ^{ - __weak GRPCCall *weakSelf = self; - [self startReadWithHandler:^(grpc_byte_buffer *message) { - if (message == NULL) { - // No more messages from the server - return; - } - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf == nil) { - grpc_byte_buffer_destroy(message); - return; - } - NSData *data = [NSData grpc_dataWithByteBuffer:message]; - grpc_byte_buffer_destroy(message); - if (!data) { - // The app doesn't have enough memory to hold the server response. We - // don't want to throw, because the app shouldn't crash for a behavior - // that's on the hands of any server to have. Instead we finish and ask - // the server to cancel. - @synchronized(strongSelf) { - strongSelf->_pendingCoreRead = NO; - [strongSelf - finishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeResourceExhausted - userInfo:@{ - NSLocalizedDescriptionKey : - @"Client does not have enough memory to " - @"hold the server response." - }]]; - [strongSelf->_wrappedCall cancel]; - } - strongSelf->_requestWriter.state = GRXWriterStateFinished; - } else { - @synchronized(strongSelf) { - [strongSelf->_responseWriteable enqueueValue:data - completionHandler:^{ - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf) { - @synchronized(strongSelf) { - strongSelf->_pendingCoreRead = NO; - [strongSelf maybeStartNextRead]; - } - } - }]; - } - } - }]; - }); -} - -#pragma mark Send headers - -- (void)sendHeaders { - // TODO (mxyan): Remove after deprecated methods are removed - uint32_t callSafetyFlags = 0; - switch (_callSafety) { - case GRPCCallSafetyDefault: - callSafetyFlags = 0; - break; - case GRPCCallSafetyIdempotentRequest: - callSafetyFlags = GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST; - break; - case GRPCCallSafetyCacheableRequest: - callSafetyFlags = GRPC_INITIAL_METADATA_CACHEABLE_REQUEST; - break; - } - - NSMutableDictionary *headers = [_requestHeaders mutableCopy]; - NSString *fetchedOauth2AccessToken; - @synchronized(self) { - fetchedOauth2AccessToken = _fetchedOauth2AccessToken; - } - if (fetchedOauth2AccessToken != nil) { - headers[@"authorization"] = [kBearerPrefix stringByAppendingString:fetchedOauth2AccessToken]; - } else if (_callOptions.oauth2AccessToken != nil) { - headers[@"authorization"] = - [kBearerPrefix stringByAppendingString:_callOptions.oauth2AccessToken]; - } - - // TODO(jcanizales): Add error handlers for async failures - GRPCOpSendMetadata *op = [[GRPCOpSendMetadata alloc] - initWithMetadata:headers - flags:callSafetyFlags - handler:nil]; // No clean-up needed after SEND_INITIAL_METADATA - dispatch_async(_callQueue, ^{ - if (!self->_unaryCall) { - [self->_wrappedCall startBatchWithOperations:@[ op ]]; - } else { - [self->_unaryOpBatch addObject:op]; - } - }); -} - -- (void)receiveNextMessages:(NSUInteger)numberOfMessages { - if (numberOfMessages == 0) { - return; - } - @synchronized(self) { - _pendingReceiveNextMessages += numberOfMessages; - - if (_state != GRXWriterStateStarted || !_callOptions.flowControlEnabled) { - return; - } - [self maybeStartNextRead]; - } -} - -#pragma mark GRXWriteable implementation - -// Only called from the call queue. The error handler will be called from the -// network queue if the write didn't succeed. -// If the call is a unary call, parameter \a errorHandler will be ignored and -// the error handler of GRPCOpSendClose will be executed in case of error. -- (void)writeMessage:(NSData *)message withErrorHandler:(void (^)(void))errorHandler { - __weak GRPCCall *weakSelf = self; - void (^resumingHandler)(void) = ^{ - // Resume the request writer. - GRPCCall *strongSelf = weakSelf; - if (strongSelf) { - strongSelf->_requestWriter.state = GRXWriterStateStarted; - if (strongSelf->_writeDone) { - strongSelf->_writeDone(); - } - } - }; - GRPCOpSendMessage *op = - [[GRPCOpSendMessage alloc] initWithMessage:message handler:resumingHandler]; - if (!_unaryCall) { - [_wrappedCall startBatchWithOperations:@[ op ] errorHandler:errorHandler]; - } else { - // Ignored errorHandler since it is the same as the one for GRPCOpSendClose. - // TODO (mxyan): unify the error handlers of all Ops into a single closure. - [_unaryOpBatch addObject:op]; - } -} - -- (void)writeValue:(id)value { - NSAssert([value isKindOfClass:[NSData class]], @"value must be of type NSData"); - - @synchronized(self) { - if (_state == GRXWriterStateFinished) { - return; - } - } - - // Pause the input and only resume it when the C layer notifies us that writes - // can proceed. - _requestWriter.state = GRXWriterStatePaused; - - dispatch_async(_callQueue, ^{ - // Write error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT - [self writeMessage:value withErrorHandler:nil]; - }); -} - -// Only called from the call queue. The error handler will be called from the -// network queue if the requests stream couldn't be closed successfully. -- (void)finishRequestWithErrorHandler:(void (^)(void))errorHandler { - if (!_unaryCall) { - [_wrappedCall startBatchWithOperations:@[ [[GRPCOpSendClose alloc] init] ] - errorHandler:errorHandler]; - } else { - [_unaryOpBatch addObject:[[GRPCOpSendClose alloc] init]]; - [_wrappedCall startBatchWithOperations:_unaryOpBatch errorHandler:errorHandler]; - } -} - -- (void)writesFinishedWithError:(NSError *)errorOrNil { - if (errorOrNil) { - [self cancel]; - } else { - dispatch_async(_callQueue, ^{ - // EOS error is not processed here. It is handled by op batch of GRPC_OP_RECV_STATUS_ON_CLIENT - [self finishRequestWithErrorHandler:nil]; - }); - } -} - -#pragma mark Invoke - -// Both handlers will eventually be called, from the network queue. Writes can start immediately -// after this. -// The first one (headersHandler), when the response headers are received. -// The second one (completionHandler), whenever the RPC finishes for any reason. -- (void)invokeCallWithHeadersHandler:(void (^)(NSDictionary *))headersHandler - completionHandler:(void (^)(NSError *, NSDictionary *))completionHandler { - dispatch_async(_callQueue, ^{ - // TODO(jcanizales): Add error handlers for async failures - [self->_wrappedCall - startBatchWithOperations:@[ [[GRPCOpRecvMetadata alloc] initWithHandler:headersHandler] ]]; - [self->_wrappedCall - startBatchWithOperations:@[ [[GRPCOpRecvStatus alloc] initWithHandler:completionHandler] ]]; - }); -} - -- (void)invokeCall { - __weak GRPCCall *weakSelf = self; - [self invokeCallWithHeadersHandler:^(NSDictionary *headers) { - // Response headers received. - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf) { - @synchronized(strongSelf) { - // it is ok to set nil because headers are only received once - strongSelf.responseHeaders = nil; - // copy the header so that the GRPCOpRecvMetadata object may be dealloc'ed - NSDictionary *copiedHeaders = - [[NSDictionary alloc] initWithDictionary:headers copyItems:YES]; - strongSelf.responseHeaders = copiedHeaders; - strongSelf->_pendingCoreRead = NO; - [strongSelf maybeStartNextRead]; - } - } - } - completionHandler:^(NSError *error, NSDictionary *trailers) { - __strong GRPCCall *strongSelf = weakSelf; - if (strongSelf) { - strongSelf.responseTrailers = trailers; - - if (error) { - NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - if (error.userInfo) { - [userInfo addEntriesFromDictionary:error.userInfo]; - } - userInfo[kGRPCTrailersKey] = strongSelf.responseTrailers; - // Since gRPC core does not guarantee the headers block being called before this block, - // responseHeaders might be nil. - userInfo[kGRPCHeadersKey] = strongSelf.responseHeaders; - error = [NSError errorWithDomain:error.domain code:error.code userInfo:userInfo]; - } - [strongSelf finishWithError:error]; - strongSelf->_requestWriter.state = GRXWriterStateFinished; - } - }]; -} - -#pragma mark GRXWriter implementation - -// Lock acquired inside startWithWriteable: -- (void)startCallWithWriteable:(id)writeable { - @synchronized(self) { - if (_state == GRXWriterStateFinished) { - return; - } - - _responseWriteable = - [[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue]; - - GRPCPooledChannel *channel = - [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions]; - _wrappedCall = [channel wrappedCallWithPath:_path - completionQueue:[GRPCCompletionQueue completionQueue] - callOptions:_callOptions]; - - if (_wrappedCall == nil) { - [self finishWithError:[NSError errorWithDomain:kGRPCErrorDomain - code:GRPCErrorCodeUnavailable - userInfo:@{ - NSLocalizedDescriptionKey : - @"Failed to create call or channel." - }]]; - return; - } - - [self sendHeaders]; - [self invokeCall]; - } - - // Now that the RPC has been initiated, request writes can start. - [_requestWriter startWithWriteable:self]; -} - -- (void)startWithWriteable:(id)writeable { - id tokenProvider = nil; - @synchronized(self) { - _state = GRXWriterStateStarted; - - // Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled). - // This makes RPCs in which the call isn't externally retained possible (as long as it is - // started before being autoreleased). Care is taken not to retain self strongly in any of the - // blocks used in this implementation, so that the life of the instance is determined by this - // retain cycle. - _retainSelf = self; - - // If _callOptions is nil, people must be using the deprecated v1 interface. In this case, - // generate the call options from the corresponding GRPCHost configs and apply other options - // that are not covered by GRPCHost. - if (_callOptions == nil) { - GRPCMutableCallOptions *callOptions = [[GRPCHost callOptionsForHost:_host] mutableCopy]; - if (_serverName.length != 0) { - callOptions.serverAuthority = _serverName; - } - if (_timeout > 0) { - callOptions.timeout = _timeout; - } - uint32_t callFlags = [GRPCCall callFlagsForHost:_host path:_path]; - if (callFlags != 0) { - if (callFlags == GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) { - _callSafety = GRPCCallSafetyIdempotentRequest; - } else if (callFlags == GRPC_INITIAL_METADATA_CACHEABLE_REQUEST) { - _callSafety = GRPCCallSafetyCacheableRequest; - } - } - - id tokenProvider = self.tokenProvider; - if (tokenProvider != nil) { - callOptions.authTokenProvider = tokenProvider; - } - _callOptions = callOptions; - } - - NSAssert(_callOptions.authTokenProvider == nil || _callOptions.oauth2AccessToken == nil, - @"authTokenProvider and oauth2AccessToken cannot be set at the same time"); - - tokenProvider = _callOptions.authTokenProvider; - } - - if (tokenProvider != nil) { - __weak typeof(self) weakSelf = self; - [tokenProvider getTokenWithHandler:^(NSString *token) { - __strong typeof(self) strongSelf = weakSelf; - if (strongSelf) { - BOOL startCall = NO; - @synchronized(strongSelf) { - if (strongSelf->_state != GRXWriterStateFinished) { - startCall = YES; - if (token) { - strongSelf->_fetchedOauth2AccessToken = [token copy]; - } - } - } - if (startCall) { - [strongSelf startCallWithWriteable:writeable]; - } - } - }]; - } else { - [self startCallWithWriteable:writeable]; - } -} - -- (void)setState:(GRXWriterState)newState { - @synchronized(self) { - // Manual transitions are only allowed from the started or paused states. - if (_state == GRXWriterStateNotStarted || _state == GRXWriterStateFinished) { - return; - } - - switch (newState) { - case GRXWriterStateFinished: - _state = newState; - // Per GRXWriter's contract, setting the state to Finished manually - // means one doesn't wish the writeable to be messaged anymore. - [_responseWriteable cancelSilently]; - _responseWriteable = nil; - return; - case GRXWriterStatePaused: - _state = newState; - return; - case GRXWriterStateStarted: - if (_state == GRXWriterStatePaused) { - _state = newState; - [self maybeStartNextRead]; - } - return; - case GRXWriterStateNotStarted: - return; - } - } -} - -@end diff --git a/src/objective-c/GRPCClient/GRPCCallOptions.h b/src/objective-c/GRPCClient/GRPCCallOptions.h index e4261b5b5f9..98511e3f5cb 100644 --- a/src/objective-c/GRPCClient/GRPCCallOptions.h +++ b/src/objective-c/GRPCClient/GRPCCallOptions.h @@ -18,11 +18,57 @@ #import -#import "GRPCTypes.h" - NS_ASSUME_NONNULL_BEGIN -@protocol GRPCInterceptorFactory; +/** + * Safety remark of a gRPC method as defined in RFC 2616 Section 9.1 + */ +typedef NS_ENUM(NSUInteger, GRPCCallSafety) { + /** Signal that there is no guarantees on how the call affects the server state. */ + GRPCCallSafetyDefault = 0, + /** Signal that the call is idempotent. gRPC is free to use PUT verb. */ + GRPCCallSafetyIdempotentRequest = 1, + /** + * Signal that the call is cacheable and will not affect server state. gRPC is free to use GET + * verb. + */ + GRPCCallSafetyCacheableRequest = 2, +}; + +// Compression algorithm to be used by a gRPC call +typedef NS_ENUM(NSUInteger, GRPCCompressionAlgorithm) { + GRPCCompressNone = 0, + GRPCCompressDeflate, + GRPCCompressGzip, + GRPCStreamCompressGzip, +}; + +// GRPCCompressAlgorithm is deprecated; use GRPCCompressionAlgorithm +typedef GRPCCompressionAlgorithm GRPCCompressAlgorithm; + +/** The transport to be used by a gRPC call */ +typedef NS_ENUM(NSUInteger, GRPCTransportType) { + GRPCTransportTypeDefault = 0, + /** gRPC internal HTTP/2 stack with BoringSSL */ + GRPCTransportTypeChttp2BoringSSL = 0, + /** Cronet stack */ + GRPCTransportTypeCronet, + /** Insecure channel. FOR TEST ONLY! */ + GRPCTransportTypeInsecure, +}; + +/** + * Implement this protocol to provide a token to gRPC when a call is initiated. + */ +@protocol GRPCAuthorizationProtocol + +/** + * This method is called when gRPC is about to start the call. When OAuth token is acquired, + * \a handler is expected to be called with \a token being the new token to be used for this call. + */ +- (void)getTokenWithHandler:(void (^)(NSString *_Nullable token))handler; + +@end @interface GRPCCallOptions : NSObject @@ -58,7 +104,7 @@ NS_ASSUME_NONNULL_BEGIN * this array. This parameter should not be modified by any interceptor and will * not take effect if done so. */ -@property(copy, readonly) NSArray> *interceptorFactories; +@property(copy, readonly) NSArray *interceptorFactories; // OAuth2 parameters. Users of gRPC may specify one of the following two parameters. @@ -146,23 +192,10 @@ NS_ASSUME_NONNULL_BEGIN @property(copy, readonly, nullable) NSString *PEMCertificateChain; /** - * Deprecated: this option is deprecated. Please use the property \a transport - * instead. - * * Select the transport type to be used for this call. */ @property(readonly) GRPCTransportType transportType; -/** - * The transport to be used for this call. Users may choose a native transport - * identifier defined in \a GRPCTransport or provided by a non-native transport - * implementation. If the option is left to be NULL, gRPC will use its default - * transport. - * - * This is currently an experimental option. - */ -@property(readonly) GRPCTransportId transport; - /** * Override the hostname during the TLS hostname validation process. */ @@ -234,7 +267,7 @@ NS_ASSUME_NONNULL_BEGIN * this array. This parameter should not be modified by any interceptor and will * not take effect if done so. */ -@property(copy, readwrite) NSArray> *interceptorFactories; +@property(copy, readwrite) NSArray *interceptorFactories; // OAuth2 parameters. Users of gRPC may specify one of the following two parameters. @@ -324,23 +357,10 @@ NS_ASSUME_NONNULL_BEGIN @property(copy, readwrite, nullable) NSString *PEMCertificateChain; /** - * Deprecated: this option is deprecated. Please use the property \a transport - * instead. - * * Select the transport type to be used for this call. */ @property(readwrite) GRPCTransportType transportType; -/** - * The transport to be used for this call. Users may choose a native transport - * identifier defined in \a GRPCTransport or provided by a non-native ttransport - * implementation. If the option is left to be NULL, gRPC will use its default - * transport. - * - * An interceptor must not change the value of this option. - */ -@property(readwrite) GRPCTransportId transport; - /** * Override the hostname during the TLS hostname validation process. */ diff --git a/src/objective-c/GRPCClient/GRPCCallOptions.m b/src/objective-c/GRPCClient/GRPCCallOptions.m index 7f88098eb6f..392e42a9d47 100644 --- a/src/objective-c/GRPCClient/GRPCCallOptions.m +++ b/src/objective-c/GRPCClient/GRPCCallOptions.m @@ -17,14 +17,13 @@ */ #import "GRPCCallOptions.h" -#import "GRPCTransport.h" #import "internal/GRPCCallOptions+Internal.h" // The default values for the call options. static NSString *const kDefaultServerAuthority = nil; static const NSTimeInterval kDefaultTimeout = 0; static const BOOL kDefaultFlowControlEnabled = NO; -static NSArray> *const kDefaultInterceptorFactories = nil; +static NSArray *const kDefaultInterceptorFactories = nil; static NSDictionary *const kDefaultInitialMetadata = nil; static NSString *const kDefaultUserAgentPrefix = nil; static const NSUInteger kDefaultResponseSizeLimit = 0; @@ -42,7 +41,6 @@ static NSString *const kDefaultPEMCertificateChain = nil; static NSString *const kDefaultOauth2AccessToken = nil; static const id kDefaultAuthTokenProvider = nil; static const GRPCTransportType kDefaultTransportType = GRPCTransportTypeChttp2BoringSSL; -static const GRPCTransportId kDefaultTransport = NULL; static NSString *const kDefaultHostNameOverride = nil; static const id kDefaultLogContext = nil; static NSString *const kDefaultChannelPoolDomain = nil; @@ -64,7 +62,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { NSString *_serverAuthority; NSTimeInterval _timeout; BOOL _flowControlEnabled; - NSArray> *_interceptorFactories; + NSArray *_interceptorFactories; NSString *_oauth2AccessToken; id _authTokenProvider; NSDictionary *_initialMetadata; @@ -82,7 +80,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { NSString *_PEMPrivateKey; NSString *_PEMCertificateChain; GRPCTransportType _transportType; - GRPCTransportId _transport; NSString *_hostNameOverride; id _logContext; NSString *_channelPoolDomain; @@ -110,7 +107,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { @synthesize PEMPrivateKey = _PEMPrivateKey; @synthesize PEMCertificateChain = _PEMCertificateChain; @synthesize transportType = _transportType; -@synthesize transport = _transport; @synthesize hostNameOverride = _hostNameOverride; @synthesize logContext = _logContext; @synthesize channelPoolDomain = _channelPoolDomain; @@ -138,7 +134,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:kDefaultPEMPrivateKey PEMCertificateChain:kDefaultPEMCertificateChain transportType:kDefaultTransportType - transport:kDefaultTransport hostNameOverride:kDefaultHostNameOverride logContext:kDefaultLogContext channelPoolDomain:kDefaultChannelPoolDomain @@ -148,7 +143,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { - (instancetype)initWithServerAuthority:(NSString *)serverAuthority timeout:(NSTimeInterval)timeout flowControlEnabled:(BOOL)flowControlEnabled - interceptorFactories:(NSArray> *)interceptorFactories + interceptorFactories:(NSArray *)interceptorFactories oauth2AccessToken:(NSString *)oauth2AccessToken authTokenProvider:(id)authTokenProvider initialMetadata:(NSDictionary *)initialMetadata @@ -166,7 +161,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:(NSString *)PEMPrivateKey PEMCertificateChain:(NSString *)PEMCertificateChain transportType:(GRPCTransportType)transportType - transport:(GRPCTransportId)transport hostNameOverride:(NSString *)hostNameOverride logContext:(id)logContext channelPoolDomain:(NSString *)channelPoolDomain @@ -199,7 +193,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { _PEMPrivateKey = [PEMPrivateKey copy]; _PEMCertificateChain = [PEMCertificateChain copy]; _transportType = transportType; - _transport = transport; _hostNameOverride = [hostNameOverride copy]; _logContext = logContext; _channelPoolDomain = [channelPoolDomain copy]; @@ -231,7 +224,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:_PEMPrivateKey PEMCertificateChain:_PEMCertificateChain transportType:_transportType - transport:_transport hostNameOverride:_hostNameOverride logContext:_logContext channelPoolDomain:_channelPoolDomain @@ -264,7 +256,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:[_PEMPrivateKey copy] PEMCertificateChain:[_PEMCertificateChain copy] transportType:_transportType - transport:_transport hostNameOverride:[_hostNameOverride copy] logContext:_logContext channelPoolDomain:[_channelPoolDomain copy] @@ -289,7 +280,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { if (!areObjectsEqual(callOptions.PEMCertificateChain, _PEMCertificateChain)) return NO; if (!areObjectsEqual(callOptions.hostNameOverride, _hostNameOverride)) return NO; if (!(callOptions.transportType == _transportType)) return NO; - if (!(TransportIdIsEqual(callOptions.transport, _transport))) return NO; if (!areObjectsEqual(callOptions.logContext, _logContext)) return NO; if (!areObjectsEqual(callOptions.channelPoolDomain, _channelPoolDomain)) return NO; if (!(callOptions.channelID == _channelID)) return NO; @@ -314,7 +304,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { result ^= _PEMCertificateChain.hash; result ^= _hostNameOverride.hash; result ^= _transportType; - result ^= TransportIdHash(_transport); result ^= _logContext.hash; result ^= _channelPoolDomain.hash; result ^= _channelID; @@ -347,7 +336,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { @dynamic PEMPrivateKey; @dynamic PEMCertificateChain; @dynamic transportType; -@dynamic transport; @dynamic hostNameOverride; @dynamic logContext; @dynamic channelPoolDomain; @@ -375,7 +363,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:kDefaultPEMPrivateKey PEMCertificateChain:kDefaultPEMCertificateChain transportType:kDefaultTransportType - transport:kDefaultTransport hostNameOverride:kDefaultHostNameOverride logContext:kDefaultLogContext channelPoolDomain:kDefaultChannelPoolDomain @@ -405,7 +392,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:_PEMPrivateKey PEMCertificateChain:_PEMCertificateChain transportType:_transportType - transport:_transport hostNameOverride:_hostNameOverride logContext:_logContext channelPoolDomain:_channelPoolDomain @@ -436,7 +422,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { PEMPrivateKey:_PEMPrivateKey PEMCertificateChain:_PEMCertificateChain transportType:_transportType - transport:_transport hostNameOverride:_hostNameOverride logContext:_logContext channelPoolDomain:_channelPoolDomain @@ -460,7 +445,7 @@ static BOOL areObjectsEqual(id obj1, id obj2) { _flowControlEnabled = flowControlEnabled; } -- (void)setInterceptorFactories:(NSArray> *)interceptorFactories { +- (void)setInterceptorFactories:(NSArray *)interceptorFactories { _interceptorFactories = interceptorFactories; } @@ -553,10 +538,6 @@ static BOOL areObjectsEqual(id obj1, id obj2) { _transportType = transportType; } -- (void)setTransport:(GRPCTransportId)transport { - _transport = transport; -} - - (void)setHostNameOverride:(NSString *)hostNameOverride { _hostNameOverride = [hostNameOverride copy]; } diff --git a/src/objective-c/GRPCClient/GRPCDispatchable.h b/src/objective-c/GRPCClient/GRPCDispatchable.h deleted file mode 100644 index 650103603d4..00000000000 --- a/src/objective-c/GRPCClient/GRPCDispatchable.h +++ /dev/null @@ -1,30 +0,0 @@ - -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * An object that processes its methods with a dispatch queue. - */ -@protocol GRPCDispatchable - -/** - * The dispatch queue where the object's methods should be run on. - */ -@property(atomic, readonly) dispatch_queue_t dispatchQueue; - -@end diff --git a/src/objective-c/GRPCClient/GRPCInterceptor.h b/src/objective-c/GRPCClient/GRPCInterceptor.h index 509749769b3..3b62c1b3ec0 100644 --- a/src/objective-c/GRPCClient/GRPCInterceptor.h +++ b/src/objective-c/GRPCClient/GRPCInterceptor.h @@ -106,20 +106,22 @@ */ #import "GRPCCall.h" -#import "GRPCDispatchable.h" NS_ASSUME_NONNULL_BEGIN @class GRPCInterceptorManager; @class GRPCInterceptor; -@class GRPCRequestOptions; -@class GRPCCallOptions; -@protocol GRPCResponseHandler; /** * The GRPCInterceptorInterface defines the request events that can occur to an interceptr. */ -@protocol GRPCInterceptorInterface +@protocol GRPCInterceptorInterface + +/** + * The queue on which all methods of this interceptor should be dispatched on. The queue must be a + * serial queue. + */ +@property(readonly) dispatch_queue_t requestDispatchQueue; /** * To start the call. This method will only be called once for each instance. @@ -169,20 +171,19 @@ NS_ASSUME_NONNULL_BEGIN * invoke shutDown method of its corresponding manager so that references to other interceptors can * be released. */ -@interface GRPCInterceptorManager : NSObject +@interface GRPCInterceptorManager : NSObject - (instancetype)init NS_UNAVAILABLE; + (instancetype) new NS_UNAVAILABLE; -- (nullable instancetype)initWithFactories:(nullable NSArray> *)factories - previousInterceptor:(nullable id)previousInterceptor - transportId:(GRPCTransportId)transportId; +- (nullable instancetype)initWithNextInterceptor:(id)nextInterceptor + NS_DESIGNATED_INITIALIZER; -/** - * Notify the manager that the interceptor has shut down and the manager should release references - * to other interceptors and stop forwarding requests/responses. - */ +/** Set the previous interceptor in the chain. Can only be set once. */ +- (void)setPreviousInterceptor:(id)previousInterceptor; + +/** Indicate shutdown of the interceptor; release the reference to other interceptors */ - (void)shutDown; // Methods to forward GRPCInterceptorInterface calls to the next interceptor @@ -234,6 +235,7 @@ NS_ASSUME_NONNULL_BEGIN @interface GRPCInterceptor : NSObject - (instancetype)init NS_UNAVAILABLE; + + (instancetype) new NS_UNAVAILABLE; /** @@ -241,7 +243,9 @@ NS_ASSUME_NONNULL_BEGIN * that this interceptor's methods are dispatched onto. */ - (nullable instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager - dispatchQueue:(dispatch_queue_t)dispatchQueue; + requestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue + NS_DESIGNATED_INITIALIZER; // Default implementation of GRPCInterceptorInterface diff --git a/src/objective-c/GRPCClient/GRPCInterceptor.m b/src/objective-c/GRPCClient/GRPCInterceptor.m index a7ffe05bddc..a385ecd7813 100644 --- a/src/objective-c/GRPCClient/GRPCInterceptor.m +++ b/src/objective-c/GRPCClient/GRPCInterceptor.m @@ -19,253 +19,117 @@ #import #import "GRPCInterceptor.h" -#import "private/GRPCTransport+Private.h" - -@interface GRPCInterceptorManager () - -@end @implementation GRPCInterceptorManager { id _nextInterceptor; id _previousInterceptor; - GRPCInterceptor *_thisInterceptor; - dispatch_queue_t _dispatchQueue; - NSArray> *_factories; - GRPCTransportId _transportId; - BOOL _shutDown; } -- (instancetype)initWithFactories:(NSArray> *)factories - previousInterceptor:(id)previousInterceptor - transportId:(nonnull GRPCTransportId)transportId { +- (instancetype)initWithNextInterceptor:(id)nextInterceptor { if ((self = [super init])) { - if (factories.count == 0) { - [NSException raise:NSInternalInconsistencyException - format:@"Interceptor manager must have factories"]; - } - _thisInterceptor = [factories[0] createInterceptorWithManager:self]; - if (_thisInterceptor == nil) { - return nil; - } - _previousInterceptor = previousInterceptor; - _factories = factories; - // Generate interceptor -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 - if (@available(iOS 8.0, macOS 10.10, *)) { - _dispatchQueue = dispatch_queue_create( - NULL, - dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); - } else { -#else - { -#endif - _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - } - dispatch_set_target_queue(_dispatchQueue, _thisInterceptor.dispatchQueue); - _transportId = transportId; + _nextInterceptor = nextInterceptor; } + return self; } -- (void)shutDown { - dispatch_async(_dispatchQueue, ^{ - self->_nextInterceptor = nil; - self->_previousInterceptor = nil; - self->_thisInterceptor = nil; - self->_shutDown = YES; - }); +- (void)setPreviousInterceptor:(id)previousInterceptor { + _previousInterceptor = previousInterceptor; } -- (void)createNextInterceptor { - NSAssert(_nextInterceptor == nil, @"Starting the next interceptor more than once"); - NSAssert(_factories.count > 0, @"Interceptor manager of transport cannot start next interceptor"); - if (_nextInterceptor != nil) { - NSLog(@"Starting the next interceptor more than once"); - return; - } - NSMutableArray> *interceptorFactories = [NSMutableArray - arrayWithArray:[_factories subarrayWithRange:NSMakeRange(1, _factories.count - 1)]]; - while (_nextInterceptor == nil) { - if (interceptorFactories.count == 0) { - _nextInterceptor = - [[GRPCTransportManager alloc] initWithTransportId:_transportId previousInterceptor:self]; - break; - } else { - _nextInterceptor = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories - previousInterceptor:self - transportId:_transportId]; - if (_nextInterceptor == nil) { - [interceptorFactories removeObjectAtIndex:0]; - } - } - } - NSAssert(_nextInterceptor != nil, @"Failed to create interceptor or transport."); - if (_nextInterceptor == nil) { - NSLog(@"Failed to create interceptor or transport."); - } +- (void)shutDown { + _nextInterceptor = nil; + _previousInterceptor = nil; } - (void)startNextInterceptorWithRequest:(GRPCRequestOptions *)requestOptions callOptions:(GRPCCallOptions *)callOptions { - if (_nextInterceptor == nil && !_shutDown) { - [self createNextInterceptor]; - } - if (_nextInterceptor == nil) { - return; + if (_nextInterceptor != nil) { + id copiedNextInterceptor = _nextInterceptor; + dispatch_async(copiedNextInterceptor.requestDispatchQueue, ^{ + [copiedNextInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; + }); } - id copiedNextInterceptor = _nextInterceptor; - dispatch_async(copiedNextInterceptor.dispatchQueue, ^{ - [copiedNextInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; - }); } - (void)writeNextInterceptorWithData:(id)data { - if (_nextInterceptor == nil && !_shutDown) { - [self createNextInterceptor]; - } - if (_nextInterceptor == nil) { - return; + if (_nextInterceptor != nil) { + id copiedNextInterceptor = _nextInterceptor; + dispatch_async(copiedNextInterceptor.requestDispatchQueue, ^{ + [copiedNextInterceptor writeData:data]; + }); } - id copiedNextInterceptor = _nextInterceptor; - dispatch_async(copiedNextInterceptor.dispatchQueue, ^{ - [copiedNextInterceptor writeData:data]; - }); } - (void)finishNextInterceptor { - if (_nextInterceptor == nil && !_shutDown) { - [self createNextInterceptor]; - } - if (_nextInterceptor == nil) { - return; + if (_nextInterceptor != nil) { + id copiedNextInterceptor = _nextInterceptor; + dispatch_async(copiedNextInterceptor.requestDispatchQueue, ^{ + [copiedNextInterceptor finish]; + }); } - id copiedNextInterceptor = _nextInterceptor; - dispatch_async(copiedNextInterceptor.dispatchQueue, ^{ - [copiedNextInterceptor finish]; - }); } - (void)cancelNextInterceptor { - if (_nextInterceptor == nil && !_shutDown) { - [self createNextInterceptor]; - } - if (_nextInterceptor == nil) { - return; + if (_nextInterceptor != nil) { + id copiedNextInterceptor = _nextInterceptor; + dispatch_async(copiedNextInterceptor.requestDispatchQueue, ^{ + [copiedNextInterceptor cancel]; + }); } - id copiedNextInterceptor = _nextInterceptor; - dispatch_async(copiedNextInterceptor.dispatchQueue, ^{ - [copiedNextInterceptor cancel]; - }); } /** Notify the next interceptor in the chain to receive more messages */ - (void)receiveNextInterceptorMessages:(NSUInteger)numberOfMessages { - if (_nextInterceptor == nil && !_shutDown) { - [self createNextInterceptor]; - } - if (_nextInterceptor == nil) { - return; + if (_nextInterceptor != nil) { + id copiedNextInterceptor = _nextInterceptor; + dispatch_async(copiedNextInterceptor.requestDispatchQueue, ^{ + [copiedNextInterceptor receiveNextMessages:numberOfMessages]; + }); } - id copiedNextInterceptor = _nextInterceptor; - dispatch_async(copiedNextInterceptor.dispatchQueue, ^{ - [copiedNextInterceptor receiveNextMessages:numberOfMessages]; - }); } // Methods to forward GRPCResponseHandler callbacks to the previous object /** Forward initial metadata to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorWithInitialMetadata:(NSDictionary *)initialMetadata { - if (_previousInterceptor == nil) { - return; +- (void)forwardPreviousInterceptorWithInitialMetadata:(nullable NSDictionary *)initialMetadata { + if ([_previousInterceptor respondsToSelector:@selector(didReceiveInitialMetadata:)]) { + id copiedPreviousInterceptor = _previousInterceptor; + dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ + [copiedPreviousInterceptor didReceiveInitialMetadata:initialMetadata]; + }); } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didReceiveInitialMetadata:initialMetadata]; - }); } /** Forward a received message to the previous interceptor in the chain */ - (void)forwardPreviousInterceptorWithData:(id)data { - if (_previousInterceptor == nil) { - return; + if ([_previousInterceptor respondsToSelector:@selector(didReceiveData:)]) { + id copiedPreviousInterceptor = _previousInterceptor; + dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ + [copiedPreviousInterceptor didReceiveData:data]; + }); } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didReceiveData:data]; - }); } /** Forward call close and trailing metadata to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata - error:(NSError *)error { - if (_previousInterceptor == nil) { - return; +- (void)forwardPreviousInterceptorCloseWithTrailingMetadata: + (nullable NSDictionary *)trailingMetadata + error:(nullable NSError *)error { + if ([_previousInterceptor respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { + id copiedPreviousInterceptor = _previousInterceptor; + dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ + [copiedPreviousInterceptor didCloseWithTrailingMetadata:trailingMetadata error:error]; + }); } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didCloseWithTrailingMetadata:trailingMetadata error:error]; - }); } /** Forward write completion to the previous interceptor in the chain */ - (void)forwardPreviousInterceptorDidWriteData { - if (_previousInterceptor == nil) { - return; - } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didWriteData]; - }); -} - -- (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; -} - -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions - callOptions:(GRPCCallOptions *)callOptions { - [_thisInterceptor startWithRequestOptions:requestOptions callOptions:callOptions]; -} - -- (void)writeData:(id)data { - [_thisInterceptor writeData:data]; -} - -- (void)finish { - [_thisInterceptor finish]; -} - -- (void)cancel { - [_thisInterceptor cancel]; -} - -- (void)receiveNextMessages:(NSUInteger)numberOfMessages { - [_thisInterceptor receiveNextMessages:numberOfMessages]; -} - -- (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata { - if ([_thisInterceptor respondsToSelector:@selector(didReceiveInitialMetadata:)]) { - [_thisInterceptor didReceiveInitialMetadata:initialMetadata]; - } -} - -- (void)didReceiveData:(id)data { - if ([_thisInterceptor respondsToSelector:@selector(didReceiveData:)]) { - [_thisInterceptor didReceiveData:data]; - } -} - -- (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - error:(nullable NSError *)error { - if ([_thisInterceptor respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { - [_thisInterceptor didCloseWithTrailingMetadata:trailingMetadata error:error]; - } -} - -- (void)didWriteData { - if ([_thisInterceptor respondsToSelector:@selector(didWriteData)]) { - [_thisInterceptor didWriteData]; + if ([_previousInterceptor respondsToSelector:@selector(didWriteData)]) { + id copiedPreviousInterceptor = _previousInterceptor; + dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ + [copiedPreviousInterceptor didWriteData]; + }); } } @@ -273,21 +137,28 @@ @implementation GRPCInterceptor { GRPCInterceptorManager *_manager; - dispatch_queue_t _dispatchQueue; + dispatch_queue_t _requestDispatchQueue; + dispatch_queue_t _responseDispatchQueue; } - (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager - dispatchQueue:(dispatch_queue_t)dispatchQueue { + requestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue { if ((self = [super init])) { _manager = interceptorManager; - _dispatchQueue = dispatchQueue; + _requestDispatchQueue = requestDispatchQueue; + _responseDispatchQueue = responseDispatchQueue; } return self; } +- (dispatch_queue_t)requestDispatchQueue { + return _requestDispatchQueue; +} + - (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; + return _responseDispatchQueue; } - (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions diff --git a/src/objective-c/GRPCClient/GRPCTransport.h b/src/objective-c/GRPCClient/GRPCTransport.h deleted file mode 100644 index d5637922152..00000000000 --- a/src/objective-c/GRPCClient/GRPCTransport.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// The interface for a transport implementation - -#import "GRPCInterceptor.h" - -NS_ASSUME_NONNULL_BEGIN - -#pragma mark Transport ID - -/** - * The default transport implementations available in gRPC. These implementations will be provided - * by gRPC by default unless explicitly excluded. - */ -extern const struct GRPCDefaultTransportImplList { - const GRPCTransportId core_secure; - const GRPCTransportId core_insecure; -} GRPCDefaultTransportImplList; - -/** Returns whether two transport id's are identical. */ -BOOL TransportIdIsEqual(GRPCTransportId lhs, GRPCTransportId rhs); - -/** Returns the hash value of a transport id. */ -NSUInteger TransportIdHash(GRPCTransportId); - -#pragma mark Transport and factory - -@protocol GRPCInterceptorInterface; -@protocol GRPCResponseHandler; -@class GRPCTransportManager; -@class GRPCRequestOptions; -@class GRPCCallOptions; -@class GRPCTransport; - -/** The factory method to create a transport. */ -@protocol GRPCTransportFactory - -- (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager; - -@end - -/** The registry of transport implementations. */ -@interface GRPCTransportRegistry : NSObject - -+ (instancetype)sharedInstance; - -/** - * Register a transport implementation with the registry. All transport implementations to be used - * in a process must register with the registry on process start-up in its +load: class method. - * Parameter \a transportId is the identifier of the implementation, and \a factory is the factory - * object to create the corresponding transport instance. - */ -- (void)registerTransportWithId:(GRPCTransportId)transportId - factory:(id)factory; - -@end - -/** - * Base class for transport implementations. All transport implementation should inherit from this - * class. - */ -@interface GRPCTransport : NSObject - -@end - -NS_ASSUME_NONNULL_END diff --git a/src/objective-c/GRPCClient/GRPCTransport.m b/src/objective-c/GRPCClient/GRPCTransport.m deleted file mode 100644 index 439acfb9cc2..00000000000 --- a/src/objective-c/GRPCClient/GRPCTransport.m +++ /dev/null @@ -1,142 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "GRPCTransport.h" - -static const GRPCTransportId gGRPCCoreSecureId = "io.grpc.transport.core.secure"; -static const GRPCTransportId gGRPCCoreInsecureId = "io.grpc.transport.core.insecure"; - -const struct GRPCDefaultTransportImplList GRPCDefaultTransportImplList = { - .core_secure = gGRPCCoreSecureId, .core_insecure = gGRPCCoreInsecureId}; - -static const GRPCTransportId gDefaultTransportId = gGRPCCoreSecureId; - -static GRPCTransportRegistry *gTransportRegistry = nil; -static dispatch_once_t initTransportRegistry; - -BOOL TransportIdIsEqual(GRPCTransportId lhs, GRPCTransportId rhs) { - // Directly comparing pointers works because we require users to use the id provided by each - // implementation, not coming up with their own string. - return lhs == rhs; -} - -NSUInteger TransportIdHash(GRPCTransportId transportId) { - if (transportId == NULL) { - transportId = gDefaultTransportId; - } - return [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding].hash; -} - -@implementation GRPCTransportRegistry { - NSMutableDictionary> *_registry; - id _defaultFactory; -} - -+ (instancetype)sharedInstance { - dispatch_once(&initTransportRegistry, ^{ - gTransportRegistry = [[GRPCTransportRegistry alloc] init]; - NSAssert(gTransportRegistry != nil, @"Unable to initialize transport registry."); - if (gTransportRegistry == nil) { - NSLog(@"Unable to initialize transport registry."); - [NSException raise:NSGenericException format:@"Unable to initialize transport registry."]; - } - }); - return gTransportRegistry; -} - -- (instancetype)init { - if ((self = [super init])) { - _registry = [NSMutableDictionary dictionary]; - } - return self; -} - -- (void)registerTransportWithId:(GRPCTransportId)transportId - factory:(id)factory { - NSString *nsTransportId = [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding]; - NSAssert(_registry[nsTransportId] == nil, @"The transport %@ has already been registered.", - nsTransportId); - if (_registry[nsTransportId] != nil) { - NSLog(@"The transport %@ has already been registered.", nsTransportId); - return; - } - _registry[nsTransportId] = factory; - - // if the default transport is registered, mark it. - if (0 == strcmp(transportId, gDefaultTransportId)) { - _defaultFactory = factory; - } -} - -- (id)getTransportFactoryWithId:(GRPCTransportId)transportId { - if (transportId == NULL) { - if (_defaultFactory == nil) { - [NSException raise:NSInvalidArgumentException - format:@"Unable to get default transport factory"]; - return nil; - } - return _defaultFactory; - } - NSString *nsTransportId = [NSString stringWithCString:transportId encoding:NSUTF8StringEncoding]; - id transportFactory = _registry[nsTransportId]; - if (transportFactory == nil) { - // User named a transport id that was not registered with the registry. - [NSException raise:NSInvalidArgumentException - format:@"Unable to get transport factory with id %s", transportId]; - return nil; - } - return transportFactory; -} - -@end - -@implementation GRPCTransport - -- (dispatch_queue_t)dispatchQueue { - [NSException raise:NSGenericException - format:@"Implementations should override the dispatch queue"]; - return nil; -} - -- (void)startWithRequestOptions:(nonnull GRPCRequestOptions *)requestOptions - callOptions:(nonnull GRPCCallOptions *)callOptions { - [NSException raise:NSGenericException - format:@"Implementations should override the methods of GRPCTransport"]; -} - -- (void)writeData:(nonnull id)data { - [NSException raise:NSGenericException - format:@"Implementations should override the methods of GRPCTransport"]; -} - -- (void)cancel { - [NSException raise:NSGenericException - format:@"Implementations should override the methods of GRPCTransport"]; -} - -- (void)finish { - [NSException raise:NSGenericException - format:@"Implementations should override the methods of GRPCTransport"]; -} - -- (void)receiveNextMessages:(NSUInteger)numberOfMessages { - [NSException raise:NSGenericException - format:@"Implementations should override the methods of GRPCTransport"]; -} - -@end diff --git a/src/objective-c/GRPCClient/GRPCTypes.h b/src/objective-c/GRPCClient/GRPCTypes.h deleted file mode 100644 index c804bca4eaa..00000000000 --- a/src/objective-c/GRPCClient/GRPCTypes.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -/** - * gRPC error codes. - * Note that a few of these are never produced by the gRPC libraries, but are of - * general utility for server applications to produce. - */ -typedef NS_ENUM(NSUInteger, GRPCErrorCode) { - /** The operation was cancelled (typically by the caller). */ - GRPCErrorCodeCancelled = 1, - - /** - * Unknown error. Errors raised by APIs that do not return enough error - * information may be converted to this error. - */ - GRPCErrorCodeUnknown = 2, - - /** - * The client specified an invalid argument. Note that this differs from - * FAILED_PRECONDITION. INVALID_ARGUMENT indicates arguments that are - * problematic regardless of the state of the server (e.g., a malformed file - * name). - */ - GRPCErrorCodeInvalidArgument = 3, - - /** - * Deadline expired before operation could complete. For operations that - * change the state of the server, this error may be returned even if the - * operation has completed successfully. For example, a successful response - * from the server could have been delayed long enough for the deadline to - * expire. - */ - GRPCErrorCodeDeadlineExceeded = 4, - - /** Some requested entity (e.g., file or directory) was not found. */ - GRPCErrorCodeNotFound = 5, - - /** Some entity that we attempted to create (e.g., file or directory) already - exists. */ - GRPCErrorCodeAlreadyExists = 6, - - /** - * The caller does not have permission to execute the specified operation. - * PERMISSION_DENIED isn't used for rejections caused by exhausting some - * resource (RESOURCE_EXHAUSTED is used instead for those errors). - * PERMISSION_DENIED doesn't indicate a failure to identify the caller - * (UNAUTHENTICATED is used instead for those errors). - */ - GRPCErrorCodePermissionDenied = 7, - - /** - * The request does not have valid authentication credentials for the - * operation (e.g. the caller's identity can't be verified). - */ - GRPCErrorCodeUnauthenticated = 16, - - /** Some resource has been exhausted, perhaps a per-user quota. */ - GRPCErrorCodeResourceExhausted = 8, - - /** - * The RPC was rejected because the server is not in a state required for the - * procedure's execution. For example, a directory to be deleted may be - * non-empty, etc. The client should not retry until the server state has been - * explicitly fixed (e.g. by performing another RPC). The details depend on - * the service being called, and should be found in the NSError's userInfo. - */ - GRPCErrorCodeFailedPrecondition = 9, - - /** - * The RPC was aborted, typically due to a concurrency issue like sequencer - * check failures, transaction aborts, etc. The client should retry at a - * higher-level (e.g., restarting a read- modify-write sequence). - */ - GRPCErrorCodeAborted = 10, - - /** - * The RPC was attempted past the valid range. E.g., enumerating past the end - * of a list. Unlike INVALID_ARGUMENT, this error indicates a problem that may - * be fixed if the system state changes. For example, an RPC to get elements - * of a list will generate INVALID_ARGUMENT if asked to return the element at - * a negative index, but it will generate OUT_OF_RANGE if asked to return the - * element at an index past the current size of the list. - */ - GRPCErrorCodeOutOfRange = 11, - - /** The procedure is not implemented or not supported/enabled in this server. - */ - GRPCErrorCodeUnimplemented = 12, - - /** - * Internal error. Means some invariant expected by the server application or - * the gRPC library has been broken. - */ - GRPCErrorCodeInternal = 13, - - /** - * The server is currently unavailable. This is most likely a transient - * condition and may be corrected by retrying with a backoff. Note that it is - * not always safe to retry non-idempotent operations. - */ - GRPCErrorCodeUnavailable = 14, - - /** Unrecoverable data loss or corruption. */ - GRPCErrorCodeDataLoss = 15, -}; - -/** - * Safety remark of a gRPC method as defined in RFC 2616 Section 9.1 - */ -typedef NS_ENUM(NSUInteger, GRPCCallSafety) { - /** - * Signal that there is no guarantees on how the call affects the server - * state. - */ - GRPCCallSafetyDefault = 0, - /** Signal that the call is idempotent. gRPC is free to use PUT verb. */ - GRPCCallSafetyIdempotentRequest = 1, - /** - * Signal that the call is cacheable and will not affect server state. gRPC is - * free to use GET verb. - */ - GRPCCallSafetyCacheableRequest = 2, -}; - -// Compression algorithm to be used by a gRPC call -typedef NS_ENUM(NSUInteger, GRPCCompressionAlgorithm) { - GRPCCompressNone = 0, - GRPCCompressDeflate, - GRPCCompressGzip, - GRPCStreamCompressGzip, -}; - -// GRPCCompressAlgorithm is deprecated; use GRPCCompressionAlgorithm -typedef GRPCCompressionAlgorithm GRPCCompressAlgorithm; - -/** The transport to be used by a gRPC call */ -typedef NS_ENUM(NSUInteger, GRPCTransportType) { - GRPCTransportTypeDefault = 0, - /** gRPC internal HTTP/2 stack with BoringSSL */ - GRPCTransportTypeChttp2BoringSSL = 0, - /** Cronet stack */ - GRPCTransportTypeCronet, - /** Insecure channel. FOR TEST ONLY! */ - GRPCTransportTypeInsecure, -}; - -/** Domain of NSError objects produced by gRPC. */ -extern NSString* _Nonnull const kGRPCErrorDomain; - -/** - * Keys used in |NSError|'s |userInfo| dictionary to store the response headers - * and trailers sent by the server. - */ -extern NSString* _Nonnull const kGRPCHeadersKey; -extern NSString* _Nonnull const kGRPCTrailersKey; - -/** The id of a transport implementation. */ -typedef char* _Nonnull GRPCTransportId; - -/** - * Implement this protocol to provide a token to gRPC when a call is initiated. - */ -@protocol GRPCAuthorizationProtocol - -/** - * This method is called when gRPC is about to start the call. When OAuth token is acquired, - * \a handler is expected to be called with \a token being the new token to be used for this call. - */ -- (void)getTokenWithHandler:(void (^_Nonnull)(NSString* _Nullable token))handler; - -@end diff --git a/src/objective-c/GRPCClient/internal_testing/GRPCCall+InternalTests.m b/src/objective-c/GRPCClient/internal_testing/GRPCCall+InternalTests.m index 8f98daa6348..1bb352f0be2 100644 --- a/src/objective-c/GRPCClient/internal_testing/GRPCCall+InternalTests.m +++ b/src/objective-c/GRPCClient/internal_testing/GRPCCall+InternalTests.m @@ -20,7 +20,7 @@ #import "GRPCCall+InternalTests.h" -#import "../private/GRPCCore/GRPCOpBatchLog.h" +#import "../private/GRPCOpBatchLog.h" @implementation GRPCCall (InternalTests) diff --git a/src/objective-c/GRPCClient/private/GRPCCore/ChannelArgsUtil.h b/src/objective-c/GRPCClient/private/ChannelArgsUtil.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/ChannelArgsUtil.h rename to src/objective-c/GRPCClient/private/ChannelArgsUtil.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/ChannelArgsUtil.m b/src/objective-c/GRPCClient/private/ChannelArgsUtil.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/ChannelArgsUtil.m rename to src/objective-c/GRPCClient/private/ChannelArgsUtil.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCall+V2API.h b/src/objective-c/GRPCClient/private/GRPCCall+V2API.h similarity index 79% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCall+V2API.h rename to src/objective-c/GRPCClient/private/GRPCCall+V2API.h index f6db3023cac..22bf16962c6 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCall+V2API.h +++ b/src/objective-c/GRPCClient/private/GRPCCall+V2API.h @@ -18,6 +18,12 @@ @interface GRPCCall (V2API) +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + callSafety:(GRPCCallSafety)safety + requestsWriter:(GRXWriter *)requestsWriter + callOptions:(GRPCCallOptions *)callOptions; + - (instancetype)initWithHost:(NSString *)host path:(NSString *)path callSafety:(GRPCCallSafety)safety diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h b/src/objective-c/GRPCClient/private/GRPCCallInternal.h similarity index 70% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h rename to src/objective-c/GRPCClient/private/GRPCCallInternal.h index 641b1fb2e8a..ac2d1cba2ec 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.h +++ b/src/objective-c/GRPCClient/private/GRPCCallInternal.h @@ -16,22 +16,20 @@ * */ -#import +#import NS_ASSUME_NONNULL_BEGIN -@protocol GRPCResponseHandler; -@class GRPCCallOptions; -@protocol GRPCChannelFactory; +@interface GRPCCall2Internal : NSObject -@interface GRPCCall2Internal : GRPCTransport +- (instancetype)init; -- (instancetype)initWithTransportManager:(GRPCTransportManager *)transportManager; +- (void)setResponseHandler:(id)responseHandler; - (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions - callOptions:(GRPCCallOptions *)callOptions; + callOptions:(nullable GRPCCallOptions *)callOptions; -- (void)writeData:(id)data; +- (void)writeData:(NSData *)data; - (void)finish; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m b/src/objective-c/GRPCClient/private/GRPCCallInternal.m similarity index 69% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m rename to src/objective-c/GRPCClient/private/GRPCCallInternal.m index ea01fcaf594..32e38158fad 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCallInternal.m +++ b/src/objective-c/GRPCClient/private/GRPCCallInternal.m @@ -19,10 +19,8 @@ #import "GRPCCallInternal.h" #import -#import #import -#import "../GRPCTransport+Private.h" #import "GRPCCall+V2API.h" @implementation GRPCCall2Internal { @@ -30,8 +28,8 @@ GRPCRequestOptions *_requestOptions; /** Options for the call. */ GRPCCallOptions *_callOptions; - /** The interceptor manager to process responses. */ - GRPCTransportManager *_transportManager; + /** The handler of responses. */ + id _handler; /** * Make use of legacy GRPCCall to make calls. Nullified when call is finished. @@ -53,28 +51,40 @@ NSUInteger _pendingReceiveNextMessages; } -- (instancetype)initWithTransportManager:(GRPCTransportManager *)transportManager { - dispatch_queue_t dispatchQueue; +- (instancetype)init { + if ((self = [super init])) { // Set queue QoS only when iOS version is 8.0 or above and Xcode version is 9.0 or above #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300 - if (@available(iOS 8.0, macOS 10.10, *)) { - dispatchQueue = dispatch_queue_create( - NULL, dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); - } else { + if (@available(iOS 8.0, macOS 10.10, *)) { + _dispatchQueue = dispatch_queue_create( + NULL, + dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0)); + } else { #else - { + { #endif - dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - } - if ((self = [super init])) { + _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); + } _pipe = [GRXBufferedPipe pipe]; - _transportManager = transportManager; - _dispatchQueue = dispatchQueue; } return self; } -- (dispatch_queue_t)dispatchQueue { +- (void)setResponseHandler:(id)responseHandler { + @synchronized(self) { + NSAssert(!_started, @"Call already started."); + if (_started) { + return; + } + _handler = responseHandler; + _initialMetadataPublished = NO; + _started = NO; + _canceled = NO; + _finished = NO; + } +} + +- (dispatch_queue_t)requestDispatchQueue { return _dispatchQueue; } @@ -92,15 +102,26 @@ return; } - GRPCCall *copiedCall = nil; @synchronized(self) { + NSAssert(_handler != nil, @"Response handler required."); + if (_handler == nil) { + NSLog(@"Invalid response handler."); + return; + } _requestOptions = requestOptions; if (callOptions == nil) { _callOptions = [[GRPCCallOptions alloc] init]; } else { _callOptions = [callOptions copy]; } + } + [self start]; +} + +- (void)start { + GRPCCall *copiedCall = nil; + @synchronized(self) { NSAssert(!_started, @"Call already started."); NSAssert(!_canceled, @"Call already canceled."); if (_started) { @@ -119,7 +140,7 @@ callOptions:_callOptions writeDone:^{ @synchronized(self) { - if (self->_transportManager) { + if (self->_handler) { [self issueDidWriteData]; } } @@ -137,7 +158,7 @@ void (^valueHandler)(id value) = ^(id value) { @synchronized(self) { - if (self->_transportManager) { + if (self->_handler) { if (!self->_initialMetadataPublished) { self->_initialMetadataPublished = YES; [self issueInitialMetadata:self->_call.responseHeaders]; @@ -150,7 +171,7 @@ }; void (^completionHandler)(NSError *errorOrNil) = ^(NSError *errorOrNil) { @synchronized(self) { - if (self->_transportManager) { + if (self->_handler) { if (!self->_initialMetadataPublished) { self->_initialMetadataPublished = YES; [self issueInitialMetadata:self->_call.responseHeaders]; @@ -186,19 +207,20 @@ _call = nil; _pipe = nil; - if (_transportManager != nil) { - [_transportManager - forwardPreviousInterceptorCloseWithTrailingMetadata:nil - error: - [NSError - errorWithDomain:kGRPCErrorDomain - code: - GRPCErrorCodeCancelled - userInfo:@{ - NSLocalizedDescriptionKey : - @"Canceled by app" - }]]; - [_transportManager shutDown]; + if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { + id copiedHandler = _handler; + _handler = nil; + dispatch_async(copiedHandler.dispatchQueue, ^{ + [copiedHandler didCloseWithTrailingMetadata:nil + error:[NSError errorWithDomain:kGRPCErrorDomain + code:GRPCErrorCodeCancelled + userInfo:@{ + NSLocalizedDescriptionKey : + @"Canceled by app" + }]]; + }); + } else { + _handler = nil; } } [copiedCall cancel]; @@ -249,25 +271,59 @@ } - (void)issueInitialMetadata:(NSDictionary *)initialMetadata { - if (initialMetadata != nil) { - [_transportManager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; + @synchronized(self) { + if (initialMetadata != nil && + [_handler respondsToSelector:@selector(didReceiveInitialMetadata:)]) { + id copiedHandler = _handler; + dispatch_async(_handler.dispatchQueue, ^{ + [copiedHandler didReceiveInitialMetadata:initialMetadata]; + }); + } } } - (void)issueMessage:(id)message { - if (message != nil) { - [_transportManager forwardPreviousInterceptorWithData:message]; + @synchronized(self) { + if (message != nil) { + if ([_handler respondsToSelector:@selector(didReceiveData:)]) { + id copiedHandler = _handler; + dispatch_async(_handler.dispatchQueue, ^{ + [copiedHandler didReceiveData:message]; + }); + } else if ([_handler respondsToSelector:@selector(didReceiveRawMessage:)]) { + id copiedHandler = _handler; + dispatch_async(_handler.dispatchQueue, ^{ + [copiedHandler didReceiveRawMessage:message]; + }); + } + } } } - (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - [_transportManager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata - error:error]; - [_transportManager shutDown]; + @synchronized(self) { + if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) { + id copiedHandler = _handler; + // Clean up _handler so that no more responses are reported to the handler. + _handler = nil; + dispatch_async(copiedHandler.dispatchQueue, ^{ + [copiedHandler didCloseWithTrailingMetadata:trailingMetadata error:error]; + }); + } else { + _handler = nil; + } + } } - (void)issueDidWriteData { - [_transportManager forwardPreviousInterceptorDidWriteData]; + @synchronized(self) { + if (_callOptions.flowControlEnabled && [_handler respondsToSelector:@selector(didWriteData)]) { + id copiedHandler = _handler; + dispatch_async(copiedHandler.dispatchQueue, ^{ + [copiedHandler didWriteData]; + }); + } + } } - (void)receiveNextMessages:(NSUInteger)numberOfMessages { diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.h rename to src/objective-c/GRPCClient/private/GRPCChannel.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m similarity index 78% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m rename to src/objective-c/GRPCClient/private/GRPCChannel.m index cd2b4313acd..1a79fb04a0d 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -20,19 +20,18 @@ #include -#import "../../internal/GRPCCallOptions+Internal.h" -#import "../GRPCTransport+Private.h" +#import "../internal/GRPCCallOptions+Internal.h" #import "ChannelArgsUtil.h" #import "GRPCChannelFactory.h" #import "GRPCChannelPool.h" #import "GRPCCompletionQueue.h" -#import "GRPCCoreFactory.h" +#import "GRPCCronetChannelFactory.h" #import "GRPCInsecureChannelFactory.h" #import "GRPCSecureChannelFactory.h" +#import "version.h" #import #import -#import @implementation GRPCChannelConfiguration @@ -51,48 +50,32 @@ } - (id)channelFactory { - if (_callOptions.transport != NULL) { - id transportFactory = - [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:_callOptions.transport]; - if (! - [transportFactory respondsToSelector:@selector(createCoreChannelFactoryWithCallOptions:)]) { - // impossible because we are using GRPCCore now - [NSException raise:NSInternalInconsistencyException - format:@"Transport factory type is wrong"]; - } - id coreTransportFactory = - (id)transportFactory; - return [coreTransportFactory createCoreChannelFactoryWithCallOptions:_callOptions]; - } else { - // To maintain backwards compatibility with tranportType - GRPCTransportType type = _callOptions.transportType; - switch (type) { - case GRPCTransportTypeChttp2BoringSSL: - // TODO (mxyan): Remove when the API is deprecated - { - NSError *error; - id factory = [GRPCSecureChannelFactory - factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates - privateKey:_callOptions.PEMPrivateKey - certChain:_callOptions.PEMCertificateChain - error:&error]; - NSAssert(factory != nil, @"Failed to create secure channel factory"); - if (factory == nil) { - NSLog(@"Error creating secure channel factory: %@", error); - } - return factory; + GRPCTransportType type = _callOptions.transportType; + switch (type) { + case GRPCTransportTypeChttp2BoringSSL: + // TODO (mxyan): Remove when the API is deprecated +#ifdef GRPC_COMPILE_WITH_CRONET + if (![GRPCCall isUsingCronet]) { +#else + { +#endif + NSError *error; + id factory = [GRPCSecureChannelFactory + factoryWithPEMRootCertificates:_callOptions.PEMRootCertificates + privateKey:_callOptions.PEMPrivateKey + certChain:_callOptions.PEMCertificateChain + error:&error]; + NSAssert(factory != nil, @"Failed to create secure channel factory"); + if (factory == nil) { + NSLog(@"Error creating secure channel factory: %@", error); } - case GRPCTransportTypeCronet: { - id transportFactory = (id)[ - [GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:gGRPCCoreCronetId]; - return [transportFactory createCoreChannelFactoryWithCallOptions:_callOptions]; + return factory; } - case GRPCTransportTypeInsecure: - return [GRPCInsecureChannelFactory sharedInstance]; - default: - NSLog(@"Unrecognized transport type"); - return nil; - } + // fallthrough + case GRPCTransportTypeCronet: + return [GRPCCronetChannelFactory sharedInstance]; + case GRPCTransportTypeInsecure: + return [GRPCInsecureChannelFactory sharedInstance]; } } @@ -215,7 +198,6 @@ } else { channelArgs = channelConfiguration.channelArgs; } - id factory = channelConfiguration.channelFactory; _unmanagedChannel = [factory createChannelWithHost:host channelArgs:channelArgs]; NSAssert(_unmanagedChannel != NULL, @"Failed to create channel"); diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelFactory.h b/src/objective-c/GRPCClient/private/GRPCChannelFactory.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelFactory.h rename to src/objective-c/GRPCClient/private/GRPCChannelFactory.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool+Test.h b/src/objective-c/GRPCClient/private/GRPCChannelPool+Test.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool+Test.h rename to src/objective-c/GRPCClient/private/GRPCChannelPool+Test.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h b/src/objective-c/GRPCClient/private/GRPCChannelPool.h similarity index 98% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h rename to src/objective-c/GRPCClient/private/GRPCChannelPool.h index b83a28a2368..e00ee69e63a 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.h @@ -18,6 +18,8 @@ #import +#import "GRPCChannelFactory.h" + NS_ASSUME_NONNULL_BEGIN @protocol GRPCChannel; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.m b/src/objective-c/GRPCClient/private/GRPCChannelPool.m similarity index 98% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.m rename to src/objective-c/GRPCClient/private/GRPCChannelPool.m index 92f52e67b75..d545793fcce 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.m +++ b/src/objective-c/GRPCClient/private/GRPCChannelPool.m @@ -18,16 +18,19 @@ #import -#import "../../internal/GRPCCallOptions+Internal.h" +#import "../internal/GRPCCallOptions+Internal.h" #import "GRPCChannel.h" #import "GRPCChannelFactory.h" #import "GRPCChannelPool+Test.h" #import "GRPCChannelPool.h" #import "GRPCCompletionQueue.h" +#import "GRPCCronetChannelFactory.h" #import "GRPCInsecureChannelFactory.h" #import "GRPCSecureChannelFactory.h" #import "GRPCWrappedCall.h" +#import "version.h" +#import #include extern const char *kCFStreamVarName; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCompletionQueue.h b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCompletionQueue.h rename to src/objective-c/GRPCClient/private/GRPCCompletionQueue.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCompletionQueue.m b/src/objective-c/GRPCClient/private/GRPCCompletionQueue.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCompletionQueue.m rename to src/objective-c/GRPCClient/private/GRPCCompletionQueue.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h deleted file mode 100644 index 83d279d2c72..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "../GRPCCoreFactory.h" - -/** - * The factory for gRPC Core + Cronet transport implementation. The - * implementation is not part of the default transports of gRPC and is for - * testing purpose only on Github. - * - * To use this transport, a user must include the GRPCCoreCronet module as a - * dependency of the project and use gGRPCCoreCronetId in call options to - * specify that this is the transport to be used for a call. - */ -@interface GRPCCoreCronetFactory : NSObject - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m deleted file mode 100644 index 5772694fc54..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCoreCronetFactory.m +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "GRPCCoreCronetFactory.h" - -#import -#import - -#import "../GRPCCallInternal.h" -#import "../GRPCCoreFactory.h" -#import "GRPCCronetChannelFactory.h" - -static GRPCCoreCronetFactory *gGRPCCoreCronetFactory = nil; -static dispatch_once_t gInitGRPCCoreCronetFactory; - -@implementation GRPCCoreCronetFactory - -+ (instancetype)sharedInstance { - dispatch_once(&gInitGRPCCoreCronetFactory, ^{ - gGRPCCoreCronetFactory = [[GRPCCoreCronetFactory alloc] init]; - }); - return gGRPCCoreCronetFactory; -} - -+ (void)load { - [[GRPCTransportRegistry sharedInstance] - registerTransportWithId:gGRPCCoreCronetId - factory:[GRPCCoreCronetFactory sharedInstance]]; -} - -- (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { - return [[GRPCCall2Internal alloc] initWithTransportManager:transportManager]; -} - -- (id)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions { - return [GRPCCronetChannelFactory sharedInstance]; -} - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h deleted file mode 100644 index 3cd312d4ad0..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import - -NS_ASSUME_NONNULL_BEGIN - -@protocol GRPCChannelFactory; -@protocol GRPCCallOptions; - -/** The interface for transport implementations that are based on Core. */ -@protocol GRPCCoreTransportFactory - -/** Get the channel factory for GRPCChannel from call options. */ -- (nullable id)createCoreChannelFactoryWithCallOptions: - (GRPCCallOptions *)callOptions; - -@end - -/** The factory for gRPC Core + CFStream + TLS secure channel transport implementation. */ -@interface GRPCCoreSecureFactory : NSObject - -@end - -/** The factory for gRPC Core + CFStream + insecure channel transport implementation. */ -@interface GRPCCoreInsecureFactory : NSObject - -@end - -NS_ASSUME_NONNULL_END diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m b/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m deleted file mode 100644 index 19d7231a203..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreFactory.m +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "GRPCCoreFactory.h" - -#import - -#import "GRPCCallInternal.h" -#import "GRPCInsecureChannelFactory.h" -#import "GRPCSecureChannelFactory.h" - -static GRPCCoreSecureFactory *gGRPCCoreSecureFactory = nil; -static GRPCCoreInsecureFactory *gGRPCCoreInsecureFactory = nil; -static dispatch_once_t gInitGRPCCoreSecureFactory; -static dispatch_once_t gInitGRPCCoreInsecureFactory; - -@implementation GRPCCoreSecureFactory - -+ (instancetype)sharedInstance { - dispatch_once(&gInitGRPCCoreSecureFactory, ^{ - gGRPCCoreSecureFactory = [[GRPCCoreSecureFactory alloc] init]; - }); - return gGRPCCoreSecureFactory; -} - -+ (void)load { - [[GRPCTransportRegistry sharedInstance] - registerTransportWithId:GRPCDefaultTransportImplList.core_secure - factory:[self sharedInstance]]; -} - -- (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { - return [[GRPCCall2Internal alloc] initWithTransportManager:transportManager]; -} - -- (id)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions { - NSError *error; - id factory = - [GRPCSecureChannelFactory factoryWithPEMRootCertificates:callOptions.PEMRootCertificates - privateKey:callOptions.PEMPrivateKey - certChain:callOptions.PEMCertificateChain - error:&error]; - if (error != nil) { - NSLog(@"Unable to create secure channel factory"); - return nil; - } - return factory; -} - -@end - -@implementation GRPCCoreInsecureFactory - -+ (instancetype)sharedInstance { - dispatch_once(&gInitGRPCCoreInsecureFactory, ^{ - gGRPCCoreInsecureFactory = [[GRPCCoreInsecureFactory alloc] init]; - }); - return gGRPCCoreInsecureFactory; -} - -+ (void)load { - [[GRPCTransportRegistry sharedInstance] - registerTransportWithId:GRPCDefaultTransportImplList.core_insecure - factory:[self sharedInstance]]; -} - -- (GRPCTransport *)createTransportWithManager:(GRPCTransportManager *)transportManager { - return [[GRPCCall2Internal alloc] initWithTransportManager:transportManager]; -} - -- (id)createCoreChannelFactoryWithCallOptions:(GRPCCallOptions *)callOptions { - return [GRPCInsecureChannelFactory sharedInstance]; -} - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.h b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.h similarity index 96% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.h rename to src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.h index 138ddf1f730..738dfdb7370 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.h +++ b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.h @@ -15,7 +15,7 @@ * limitations under the License. * */ -#import "../GRPCChannelFactory.h" +#import "GRPCChannelFactory.h" @class GRPCChannel; typedef struct stream_engine stream_engine; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m similarity index 76% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.m rename to src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m index da3f3afd855..5bcb021dc4b 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/GRPCCronetChannelFactory.m +++ b/src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m @@ -18,8 +18,10 @@ #import "GRPCCronetChannelFactory.h" -#import "../ChannelArgsUtil.h" -#import "../GRPCChannel.h" +#import "ChannelArgsUtil.h" +#import "GRPCChannel.h" + +#ifdef GRPC_COMPILE_WITH_CRONET #import #include @@ -57,3 +59,21 @@ } @end + +#else + +@implementation GRPCCronetChannelFactory + ++ (instancetype)sharedInstance { + NSAssert(NO, @"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."); + return nil; +} + +- (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args { + NSAssert(NO, @"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."); + return NULL; +} + +@end + +#endif diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.h b/src/objective-c/GRPCClient/private/GRPCHost.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.h rename to src/objective-c/GRPCClient/private/GRPCHost.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m similarity index 82% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m rename to src/objective-c/GRPCClient/private/GRPCHost.m index 1f6a25ff78f..63ffc927411 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -21,16 +21,17 @@ #import #import #import -#import #include #include -#import "../../internal/GRPCCallOptions+Internal.h" +#import "../internal/GRPCCallOptions+Internal.h" #import "GRPCChannelFactory.h" #import "GRPCCompletionQueue.h" +#import "GRPCCronetChannelFactory.h" #import "GRPCSecureChannelFactory.h" #import "NSDictionary+GRPC.h" +#import "version.h" NS_ASSUME_NONNULL_BEGIN @@ -112,12 +113,20 @@ static NSMutableDictionary *gHostCache; options.PEMPrivateKey = _PEMPrivateKey; options.PEMCertificateChain = _PEMCertificateChain; options.hostNameOverride = _hostNameOverride; - if (_transportType == GRPCTransportTypeInsecure) { - options.transport = GRPCDefaultTransportImplList.core_insecure; - } else if ([GRPCCall isUsingCronet]) { - options.transport = gGRPCCoreCronetId; - } else { - options.transport = GRPCDefaultTransportImplList.core_secure; +#ifdef GRPC_COMPILE_WITH_CRONET + // By old API logic, insecure channel precedes Cronet channel; Cronet channel preceeds default + // channel. + if ([GRPCCall isUsingCronet]) { + if (_transportType == GRPCTransportTypeInsecure) { + options.transportType = GRPCTransportTypeInsecure; + } else { + NSAssert(_transportType == GRPCTransportTypeDefault, @"Invalid transport type"); + options.transportType = GRPCTransportTypeCronet; + } + } else +#endif + { + options.transportType = _transportType; } options.logContext = _logContext; @@ -126,14 +135,16 @@ static NSMutableDictionary *gHostCache; + (GRPCCallOptions *)callOptionsForHost:(NSString *)host { // TODO (mxyan): Remove when old API is deprecated + NSURL *hostURL = [NSURL URLWithString:[@"https://" stringByAppendingString:host]]; + if (hostURL.host && hostURL.port == nil) { + host = [hostURL.host stringByAppendingString:@":443"]; + } + GRPCCallOptions *callOptions = nil; @synchronized(gHostCache) { - GRPCHost *hostConfig = [GRPCHost hostWithAddress:host]; - callOptions = [hostConfig callOptions]; + callOptions = [gHostCache[host] callOptions]; } - NSAssert(callOptions != nil, @"Unable to create call options object"); if (callOptions == nil) { - NSLog(@"Unable to create call options object"); callOptions = [[GRPCCallOptions alloc] init]; } return callOptions; diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCInsecureChannelFactory.h b/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCInsecureChannelFactory.h rename to src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCInsecureChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCInsecureChannelFactory.m rename to src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCOpBatchLog.h b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCOpBatchLog.h rename to src/objective-c/GRPCClient/private/GRPCOpBatchLog.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCOpBatchLog.m b/src/objective-c/GRPCClient/private/GRPCOpBatchLog.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCOpBatchLog.m rename to src/objective-c/GRPCClient/private/GRPCOpBatchLog.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCReachabilityFlagNames.xmacro.h b/src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCReachabilityFlagNames.xmacro.h rename to src/objective-c/GRPCClient/private/GRPCReachabilityFlagNames.xmacro.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.h b/src/objective-c/GRPCClient/private/GRPCRequestHeaders.h similarity index 95% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.h rename to src/objective-c/GRPCClient/private/GRPCRequestHeaders.h index 0fced0c385a..545ff1cea82 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.h +++ b/src/objective-c/GRPCClient/private/GRPCRequestHeaders.h @@ -18,7 +18,7 @@ #import -#import +#import "../GRPCCall.h" @interface GRPCRequestHeaders : NSMutableDictionary diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.m b/src/objective-c/GRPCClient/private/GRPCRequestHeaders.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCRequestHeaders.m rename to src/objective-c/GRPCClient/private/GRPCRequestHeaders.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCSecureChannelFactory.h b/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCSecureChannelFactory.h rename to src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCSecureChannelFactory.m b/src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCSecureChannelFactory.m rename to src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m diff --git a/src/objective-c/GRPCClient/private/GRPCTransport+Private.h b/src/objective-c/GRPCClient/private/GRPCTransport+Private.h deleted file mode 100644 index 2dc7357c363..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCTransport+Private.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Private interfaces of the transport registry. - */ -@interface GRPCTransportRegistry (Private) - -/** - * Get a transport implementation's factory by its transport id. If the transport id was not - * registered with the registry, the default transport factory (core + secure) is returned. If the - * default transport does not exist, an exception is thrown. - */ -- (id)getTransportFactoryWithId:(GRPCTransportId)transportId; - -@end - -@interface GRPCTransportManager : NSObject - -- (instancetype)initWithTransportId:(GRPCTransportId)transportId - previousInterceptor:(id)previousInterceptor; - -/** - * Notify the manager that the transport has shut down and the manager should release references to - * its response handler and stop forwarding requests/responses. - */ -- (void)shutDown; - -/** Forward initial metadata to the previous interceptor in the interceptor chain */ -- (void)forwardPreviousInterceptorWithInitialMetadata:(nullable NSDictionary *)initialMetadata; - -/** Forward a received message to the previous interceptor in the interceptor chain */ -- (void)forwardPreviousInterceptorWithData:(nullable id)data; - -/** Forward call close and trailing metadata to the previous interceptor in the interceptor chain */ -- (void)forwardPreviousInterceptorCloseWithTrailingMetadata: - (nullable NSDictionary *)trailingMetadata - error:(nullable NSError *)error; - -/** Forward write completion to the previous interceptor in the interceptor chain */ -- (void)forwardPreviousInterceptorDidWriteData; - -@end - -NS_ASSUME_NONNULL_END diff --git a/src/objective-c/GRPCClient/private/GRPCTransport+Private.m b/src/objective-c/GRPCClient/private/GRPCTransport+Private.m deleted file mode 100644 index 9072f7afbe2..00000000000 --- a/src/objective-c/GRPCClient/private/GRPCTransport+Private.m +++ /dev/null @@ -1,131 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "GRPCTransport+Private.h" - -#import - -@implementation GRPCTransportManager { - GRPCTransportId _transportId; - GRPCTransport *_transport; - id _previousInterceptor; - dispatch_queue_t _dispatchQueue; -} - -- (instancetype)initWithTransportId:(GRPCTransportId)transportId - previousInterceptor:(id)previousInterceptor { - if ((self = [super init])) { - id factory = - [[GRPCTransportRegistry sharedInstance] getTransportFactoryWithId:transportId]; - - _transport = [factory createTransportWithManager:self]; - NSAssert(_transport != nil, @"Failed to create transport with id: %s", transportId); - if (_transport == nil) { - NSLog(@"Failed to create transport with id: %s", transportId); - return nil; - } - _previousInterceptor = previousInterceptor; - _dispatchQueue = _transport.dispatchQueue; - _transportId = transportId; - } - return self; -} - -- (void)shutDown { - dispatch_async(_dispatchQueue, ^{ - self->_transport = nil; - self->_previousInterceptor = nil; - }); -} - -- (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; -} - -- (void)startWithRequestOptions:(GRPCRequestOptions *)requestOptions - callOptions:(GRPCCallOptions *)callOptions { - if (_transportId != callOptions.transport) { - [NSException raise:NSInvalidArgumentException - format:@"Interceptors cannot change the call option 'transport'"]; - return; - } - [_transport startWithRequestOptions:requestOptions callOptions:callOptions]; -} - -- (void)writeData:(id)data { - [_transport writeData:data]; -} - -- (void)finish { - [_transport finish]; -} - -- (void)cancel { - [_transport cancel]; -} - -- (void)receiveNextMessages:(NSUInteger)numberOfMessages { - [_transport receiveNextMessages:numberOfMessages]; -} - -/** Forward initial metadata to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorWithInitialMetadata:(NSDictionary *)initialMetadata { - if (initialMetadata == nil || _previousInterceptor == nil) { - return; - } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didReceiveInitialMetadata:initialMetadata]; - }); -} - -/** Forward a received message to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorWithData:(id)data { - if (data == nil || _previousInterceptor == nil) { - return; - } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didReceiveData:data]; - }); -} - -/** Forward call close and trailing metadata to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata - error:(NSError *)error { - if (_previousInterceptor == nil) { - return; - } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didCloseWithTrailingMetadata:trailingMetadata error:error]; - }); -} - -/** Forward write completion to the previous interceptor in the chain */ -- (void)forwardPreviousInterceptorDidWriteData { - if (_previousInterceptor == nil) { - return; - } - id copiedPreviousInterceptor = _previousInterceptor; - dispatch_async(copiedPreviousInterceptor.dispatchQueue, ^{ - [copiedPreviousInterceptor didWriteData]; - }); -} - -@end diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCWrappedCall.h b/src/objective-c/GRPCClient/private/GRPCWrappedCall.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCWrappedCall.h rename to src/objective-c/GRPCClient/private/GRPCWrappedCall.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/GRPCWrappedCall.m rename to src/objective-c/GRPCClient/private/GRPCWrappedCall.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSData+GRPC.h b/src/objective-c/GRPCClient/private/NSData+GRPC.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/NSData+GRPC.h rename to src/objective-c/GRPCClient/private/NSData+GRPC.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSData+GRPC.m b/src/objective-c/GRPCClient/private/NSData+GRPC.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/NSData+GRPC.m rename to src/objective-c/GRPCClient/private/NSData+GRPC.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSDictionary+GRPC.h b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/NSDictionary+GRPC.h rename to src/objective-c/GRPCClient/private/NSDictionary+GRPC.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/NSDictionary+GRPC.m rename to src/objective-c/GRPCClient/private/NSDictionary+GRPC.m diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSError+GRPC.h b/src/objective-c/GRPCClient/private/NSError+GRPC.h similarity index 100% rename from src/objective-c/GRPCClient/private/GRPCCore/NSError+GRPC.h rename to src/objective-c/GRPCClient/private/NSError+GRPC.h diff --git a/src/objective-c/GRPCClient/private/GRPCCore/NSError+GRPC.m b/src/objective-c/GRPCClient/private/NSError+GRPC.m similarity index 96% rename from src/objective-c/GRPCClient/private/GRPCCore/NSError+GRPC.m rename to src/objective-c/GRPCClient/private/NSError+GRPC.m index 5b5fc6263c5..3eefed88d63 100644 --- a/src/objective-c/GRPCClient/private/GRPCCore/NSError+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSError+GRPC.m @@ -18,9 +18,10 @@ #import "NSError+GRPC.h" -#import #include +NSString *const kGRPCErrorDomain = @"io.grpc"; + @implementation NSError (GRPC) + (instancetype)grpc_errorFromStatusCode:(grpc_status_code)statusCode details:(const char *)details diff --git a/src/objective-c/GRPCClient/version.h b/src/objective-c/GRPCClient/private/version.h similarity index 100% rename from src/objective-c/GRPCClient/version.h rename to src/objective-c/GRPCClient/private/version.h diff --git a/src/objective-c/ProtoRPC/ProtoRPC.h b/src/objective-c/ProtoRPC/ProtoRPC.h index c91adc7b7cd..12db46adeda 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.h +++ b/src/objective-c/ProtoRPC/ProtoRPC.h @@ -17,16 +17,12 @@ */ #import - -// import legacy header for compatibility with users using the ProtoRPC interface -#import "ProtoRPCLegacy.h" +#import #import "ProtoMethod.h" NS_ASSUME_NONNULL_BEGIN -@class GRPCRequestOptions; -@class GRPCCallOptions; @class GPBMessage; /** An object can implement this protocol to receive responses from server from a call. */ @@ -164,3 +160,35 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wnullability-completeness" + +__attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC + : GRPCCall + + /** + * host parameter should not contain the scheme (http:// or https://), only the name or IP + * addr and the port number, for example @"localhost:5050". + */ + - + (instancetype)initWithHost : (NSString *)host method + : (GRPCProtoMethod *)method requestsWriter : (GRXWriter *)requestsWriter responseClass + : (Class)responseClass responsesWriteable + : (id)responsesWriteable NS_DESIGNATED_INITIALIZER; + +- (void)start; +@end + +/** + * This subclass is empty now. Eventually we'll remove ProtoRPC class + * to avoid potential naming conflict + */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + @interface GRPCProtoCall : ProtoRPC +#pragma clang diagnostic pop + + @end + +#pragma clang diagnostic pop diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index dbfa3c0f23d..4700fdd1124 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -27,6 +27,24 @@ #import #import +/** + * Generate an NSError object that represents a failure in parsing a proto class. + */ +static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError) { + NSDictionary *info = @{ + NSLocalizedDescriptionKey : @"Unable to parse response from the server", + NSLocalizedRecoverySuggestionErrorKey : + @"If this RPC is idempotent, retry " + @"with exponential backoff. Otherwise, query the server status before " + @"retrying.", + NSUnderlyingErrorKey : parsingError, + @"Expected class" : expectedClass, + @"Received value" : proto, + }; + // TODO(jcanizales): Use kGRPCErrorDomain and GRPCErrorCodeInternal when they're public. + return [NSError errorWithDomain:@"io.grpc" code:13 userInfo:info]; +} + @implementation GRPCUnaryProtoCall { GRPCStreamingProtoCall *_call; GPBMessage *_message; @@ -273,3 +291,76 @@ } @end + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-implementations" +@implementation ProtoRPC { +#pragma clang diagnostic pop + id _responseWriteable; +} + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-designated-initializers" +- (instancetype)initWithHost:(NSString *)host + path:(NSString *)path + requestsWriter:(GRXWriter *)requestsWriter { + [NSException raise:NSInvalidArgumentException + format:@"Please use ProtoRPC's designated initializer instead."]; + return nil; +} +#pragma clang diagnostic pop + +// Designated initializer +- (instancetype)initWithHost:(NSString *)host + method:(GRPCProtoMethod *)method + requestsWriter:(GRXWriter *)requestsWriter + responseClass:(Class)responseClass + responsesWriteable:(id)responsesWriteable { + // Because we can't tell the type system to constrain the class, we need to check at runtime: + if (![responseClass respondsToSelector:@selector(parseFromData:error:)]) { + [NSException raise:NSInvalidArgumentException + format:@"A protobuf class to parse the responses must be provided."]; + } + // A writer that serializes the proto messages to send. + GRXWriter *bytesWriter = [requestsWriter map:^id(GPBMessage *proto) { + if (![proto isKindOfClass:[GPBMessage class]]) { + [NSException raise:NSInvalidArgumentException + format:@"Request must be a proto message: %@", proto]; + } + return [proto data]; + }]; + if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) { + __weak ProtoRPC *weakSelf = self; + + // A writeable that parses the proto messages received. + _responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { + // TODO(jcanizales): This is done in the main thread, and needs to happen in another thread. + NSError *error = nil; + id parsed = [responseClass parseFromData:value error:&error]; + if (parsed) { + [responsesWriteable writeValue:parsed]; + } else { + [weakSelf finishWithError:ErrorForBadProto(value, responseClass, error)]; + } + } + completionHandler:^(NSError *errorOrNil) { + [responsesWriteable writesFinishedWithError:errorOrNil]; + }]; + } + return self; +} + +- (void)start { + [self startWithWriteable:_responseWriteable]; +} + +- (void)startWithWriteable:(id)writeable { + [super startWithWriteable:writeable]; + // Break retain cycles. + _responseWriteable = nil; +} +@end + +@implementation GRPCProtoCall + +@end diff --git a/src/objective-c/ProtoRPC/ProtoRPCLegacy.h b/src/objective-c/ProtoRPC/ProtoRPCLegacy.h deleted file mode 100644 index b8d4003f695..00000000000 --- a/src/objective-c/ProtoRPC/ProtoRPCLegacy.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import - -// Import category headers for Swift build -#import -#import -#import -#import -#import -#import - -@class GRPCProtoMethod; -@class GRXWriter; -@protocol GRXWriteable; - -__attribute__((deprecated("Please use GRPCProtoCall."))) @interface ProtoRPC - : GRPCCall - - /** - * host parameter should not contain the scheme (http:// or https://), only the name or IP - * addr and the port number, for example @"localhost:5050". - */ - - - (instancetype)initWithHost : (NSString *)host method - : (GRPCProtoMethod *)method requestsWriter : (GRXWriter *)requestsWriter responseClass - : (Class)responseClass responsesWriteable - : (id)responsesWriteable NS_DESIGNATED_INITIALIZER; - -- (void)start; - -@end - -/** - * This subclass is empty now. Eventually we'll remove ProtoRPC class - * to avoid potential naming conflict - */ -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - @interface GRPCProtoCall - : ProtoRPC -#pragma clang diagnostic pop - - @end - - /** - * Generate an NSError object that represents a failure in parsing a proto class. For gRPC - * internal use only. - */ - NSError * - ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError); diff --git a/src/objective-c/ProtoRPC/ProtoRPCLegacy.m b/src/objective-c/ProtoRPC/ProtoRPCLegacy.m deleted file mode 100644 index 4ba93674063..00000000000 --- a/src/objective-c/ProtoRPC/ProtoRPCLegacy.m +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "ProtoRPCLegacy.h" - -#import "ProtoMethod.h" - -#if GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS -#import -#else -#import -#endif -#import -#import -#import - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-implementations" -@implementation ProtoRPC { -#pragma clang diagnostic pop - id _responseWriteable; -} - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-designated-initializers" -- (instancetype)initWithHost:(NSString *)host - path:(NSString *)path - requestsWriter:(GRXWriter *)requestsWriter { - [NSException raise:NSInvalidArgumentException - format:@"Please use ProtoRPC's designated initializer instead."]; - return nil; -} -#pragma clang diagnostic pop - -// Designated initializer -- (instancetype)initWithHost:(NSString *)host - method:(GRPCProtoMethod *)method - requestsWriter:(GRXWriter *)requestsWriter - responseClass:(Class)responseClass - responsesWriteable:(id)responsesWriteable { - // Because we can't tell the type system to constrain the class, we need to check at runtime: - if (![responseClass respondsToSelector:@selector(parseFromData:error:)]) { - [NSException raise:NSInvalidArgumentException - format:@"A protobuf class to parse the responses must be provided."]; - } - // A writer that serializes the proto messages to send. - GRXWriter *bytesWriter = [requestsWriter map:^id(GPBMessage *proto) { - if (![proto isKindOfClass:[GPBMessage class]]) { - [NSException raise:NSInvalidArgumentException - format:@"Request must be a proto message: %@", proto]; - } - return [proto data]; - }]; - if ((self = [super initWithHost:host path:method.HTTPPath requestsWriter:bytesWriter])) { - __weak ProtoRPC *weakSelf = self; - - // A writeable that parses the proto messages received. - _responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { - // TODO(jcanizales): This is done in the main thread, and needs to happen in another thread. - NSError *error = nil; - id parsed = [responseClass parseFromData:value error:&error]; - if (parsed) { - [responsesWriteable writeValue:parsed]; - } else { - [weakSelf finishWithError:ErrorForBadProto(value, responseClass, error)]; - } - } - completionHandler:^(NSError *errorOrNil) { - [responsesWriteable writesFinishedWithError:errorOrNil]; - }]; - } - return self; -} - -- (void)start { - [self startWithWriteable:_responseWriteable]; -} - -- (void)startWithWriteable:(id)writeable { - [super startWithWriteable:writeable]; - // Break retain cycles. - _responseWriteable = nil; -} -@end - -@implementation GRPCProtoCall - -@end - -/** - * Generate an NSError object that represents a failure in parsing a proto class. - */ -NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsingError) { - NSDictionary *info = @{ - NSLocalizedDescriptionKey : @"Unable to parse response from the server", - NSLocalizedRecoverySuggestionErrorKey : - @"If this RPC is idempotent, retry " - @"with exponential backoff. Otherwise, query the server status before " - @"retrying.", - NSUnderlyingErrorKey : parsingError, - @"Expected class" : expectedClass, - @"Received value" : proto, - }; - // TODO(jcanizales): Use kGRPCErrorDomain and GRPCErrorCodeInternal when they're public. - return [NSError errorWithDomain:@"io.grpc" code:13 userInfo:info]; -} diff --git a/src/objective-c/ProtoRPC/ProtoService.h b/src/objective-c/ProtoRPC/ProtoService.h index fd8a86bb2b2..900ec8d0e1e 100644 --- a/src/objective-c/ProtoRPC/ProtoService.h +++ b/src/objective-c/ProtoRPC/ProtoService.h @@ -18,12 +18,14 @@ #import -#import -#import "ProtoRPC.h" - +@class GRPCProtoCall; @protocol GRXWriteable; @class GRXWriter; @class GRPCCallOptions; +@class GRPCProtoCall; +@class GRPCUnaryProtoCall; +@class GRPCStreamingProtoCall; +@protocol GRPCProtoResponseHandler; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" @@ -36,6 +38,15 @@ __attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoServ : (nonnull NSString *)packageName serviceName : (nonnull NSString *)serviceName callOptions : (nullable GRPCCallOptions *)callOptions NS_DESIGNATED_INITIALIZER; +- (instancetype)initWithHost:(NSString *)host + packageName:(NSString *)packageName + serviceName:(NSString *)serviceName; + +- (GRPCProtoCall *)RPCToMethod:(NSString *)method + requestsWriter:(GRXWriter *)requestsWriter + responseClass:(Class)responseClass + responsesWriteable:(id)responsesWriteable; + - (nullable GRPCUnaryProtoCall *)RPCToMethod:(nonnull NSString *)method message:(nonnull id)message responseHandler:(nonnull id)handler @@ -47,18 +58,6 @@ __attribute__((deprecated("Please use GRPCProtoService."))) @interface ProtoServ callOptions:(nullable GRPCCallOptions *)callOptions responseClass:(nonnull Class)responseClass; -@end - - @interface ProtoService(Legacy) - - - (instancetype)initWithHost : (NSString *)host packageName - : (NSString *)packageName serviceName : (NSString *)serviceName; - -- (GRPCProtoCall *)RPCToMethod:(NSString *)method - requestsWriter:(GRXWriter *)requestsWriter - responseClass:(Class)responseClass - responsesWriteable:(id)responsesWriteable; - @end #pragma clang diagnostic pop diff --git a/src/objective-c/ProtoRPC/ProtoService.m b/src/objective-c/ProtoRPC/ProtoService.m index e84cab8903f..80a1f2f226c 100644 --- a/src/objective-c/ProtoRPC/ProtoService.m +++ b/src/objective-c/ProtoRPC/ProtoService.m @@ -29,21 +29,15 @@ #pragma clang diagnostic ignored "-Wdeprecated-implementations" @implementation ProtoService { #pragma clang diagnostic pop - - GRPCCallOptions *_callOptions; NSString *_host; NSString *_packageName; NSString *_serviceName; + GRPCCallOptions *_callOptions; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wnonnull" -// Do not call the default init method - (instancetype)init { - [NSException raise:NSGenericException format:@"Do not call init method of ProtoService"]; - return [self initWithHost:nil packageName:nil serviceName:nil callOptions:nil]; + return [self initWithHost:nil packageName:nil serviceName:nil]; } -#pragma clang diagnostic pop // Designated initializer - (instancetype)initWithHost:(NSString *)host @@ -64,6 +58,38 @@ return self; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-designated-initializers" +// Do not call designated initializer here due to nullability incompatibility. This method is from +// old API and does not assert on nullability of the parameters. + +- (instancetype)initWithHost:(NSString *)host + packageName:(NSString *)packageName + serviceName:(NSString *)serviceName { + if ((self = [super init])) { + _host = [host copy]; + _packageName = [packageName copy]; + _serviceName = [serviceName copy]; + _callOptions = nil; + } + return self; +} + +#pragma clang diagnostic pop + +- (GRPCProtoCall *)RPCToMethod:(NSString *)method + requestsWriter:(GRXWriter *)requestsWriter + responseClass:(Class)responseClass + responsesWriteable:(id)responsesWriteable { + GRPCProtoMethod *methodName = + [[GRPCProtoMethod alloc] initWithPackage:_packageName service:_serviceName method:method]; + return [[GRPCProtoCall alloc] initWithHost:_host + method:methodName + requestsWriter:requestsWriter + responseClass:responseClass + responsesWriteable:responsesWriteable]; +} + - (GRPCUnaryProtoCall *)RPCToMethod:(NSString *)method message:(id)message responseHandler:(id)handler diff --git a/src/objective-c/ProtoRPC/ProtoServiceLegacy.h b/src/objective-c/ProtoRPC/ProtoServiceLegacy.h deleted file mode 100644 index 7b0b7a4de7e..00000000000 --- a/src/objective-c/ProtoRPC/ProtoServiceLegacy.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import "ProtoService.h" - -@class GRPCProtoCall; -@class GRXWriter; -@protocol GRXWriteable; diff --git a/src/objective-c/ProtoRPC/ProtoServiceLegacy.m b/src/objective-c/ProtoRPC/ProtoServiceLegacy.m deleted file mode 100644 index 6aa64955381..00000000000 --- a/src/objective-c/ProtoRPC/ProtoServiceLegacy.m +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * Copyright 2019 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#import - -#import "ProtoMethod.h" -#import "ProtoRPCLegacy.h" -#import "ProtoService.h" - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-implementations" -@implementation ProtoService (Legacy) -#pragma clang diagnostic pop - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wobjc-designated-initializers" -// Do not call designated initializer here due to nullability incompatibility. This method is from -// old API and does not assert on nullability of the parameters. - -- (instancetype)initWithHost:(NSString *)host - packageName:(NSString *)packageName - serviceName:(NSString *)serviceName { - if ((self = [super init])) { - Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host"); - Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName"); - Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName"); - - object_setIvar(self, hostIvar, [host copy]); - object_setIvar(self, packageNameIvar, [packageName copy]); - object_setIvar(self, serviceNameIvar, [serviceName copy]); - } - return self; -} -#pragma clang diagnostic pop - -- (GRPCProtoCall *)RPCToMethod:(NSString *)method - requestsWriter:(GRXWriter *)requestsWriter - responseClass:(Class)responseClass - responsesWriteable:(id)responsesWriteable { - Ivar hostIvar = class_getInstanceVariable([ProtoService class], "_host"); - Ivar packageNameIvar = class_getInstanceVariable([ProtoService class], "_packageName"); - Ivar serviceNameIvar = class_getInstanceVariable([ProtoService class], "_serviceName"); - NSString *host = object_getIvar(self, hostIvar); - NSString *packageName = object_getIvar(self, packageNameIvar); - NSString *serviceName = object_getIvar(self, serviceNameIvar); - - GRPCProtoMethod *methodName = - [[GRPCProtoMethod alloc] initWithPackage:packageName service:serviceName method:method]; - return [[GRPCProtoCall alloc] initWithHost:host - method:methodName - requestsWriter:requestsWriter - responseClass:responseClass - responsesWriteable:responsesWriteable]; -} - -@end diff --git a/src/objective-c/examples/tvOS-sample/tvOS-sample/ViewController.m b/src/objective-c/examples/tvOS-sample/tvOS-sample/ViewController.m index 9c466260121..c94ee8c2569 100644 --- a/src/objective-c/examples/tvOS-sample/tvOS-sample/ViewController.m +++ b/src/objective-c/examples/tvOS-sample/tvOS-sample/ViewController.m @@ -25,8 +25,6 @@ #import "src/objective-c/examples/RemoteTestClient/Messages.pbobjc.h" #import "src/objective-c/examples/RemoteTestClient/Test.pbrpc.h" #endif -#import -#import @interface ViewController () diff --git a/src/objective-c/examples/watchOS-sample/WatchKit-Extension/InterfaceController.m b/src/objective-c/examples/watchOS-sample/WatchKit-Extension/InterfaceController.m index ce204a9c146..3e97767cf0c 100644 --- a/src/objective-c/examples/watchOS-sample/WatchKit-Extension/InterfaceController.m +++ b/src/objective-c/examples/watchOS-sample/WatchKit-Extension/InterfaceController.m @@ -24,8 +24,6 @@ #import "src/objective-c/examples/RemoteTestClient/Messages.pbobjc.h" #import "src/objective-c/examples/RemoteTestClient/Test.pbrpc.h" #endif -#import -#import @interface InterfaceController () diff --git a/src/objective-c/tests/BUILD b/src/objective-c/tests/BUILD index 65a32d742a9..fed92596b17 100644 --- a/src/objective-c/tests/BUILD +++ b/src/objective-c/tests/BUILD @@ -95,12 +95,19 @@ tvos_application( deps = ["host-lib"], ) +grpc_objc_testing_library( + name = "CronetConfig", + srcs = ["ConfigureCronet.m"], + hdrs = ["ConfigureCronet.h"], +) + grpc_objc_testing_library( name = "InteropTests-lib", hdrs = ["InteropTests/InteropTests.h"], srcs = ["InteropTests/InteropTests.m"], deps = [ ":InteropTestsBlockCallbacks-lib", + ":CronetConfig", ], ) @@ -193,6 +200,7 @@ ios_unit_test( ":InteropTestsRemote-lib", ":InteropTestsLocalSSL-lib", ":InteropTestsLocalCleartext-lib", + # ":InteropTestsMulitpleChannels-lib", # needs Cronet ], test_host = ":ios-host", ) diff --git a/src/objective-c/tests/ConfigureCronet.h b/src/objective-c/tests/ConfigureCronet.h index ba0efc4df66..cc5c038f3c6 100644 --- a/src/objective-c/tests/ConfigureCronet.h +++ b/src/objective-c/tests/ConfigureCronet.h @@ -16,6 +16,8 @@ * */ +#ifdef GRPC_COMPILE_WITH_CRONET + #ifdef __cplusplus extern "C" { #endif @@ -28,3 +30,5 @@ void configureCronet(void); #ifdef __cplusplus } #endif + +#endif diff --git a/src/objective-c/tests/ConfigureCronet.m b/src/objective-c/tests/ConfigureCronet.m index 6fc7e0ee9f5..ab137e28cad 100644 --- a/src/objective-c/tests/ConfigureCronet.m +++ b/src/objective-c/tests/ConfigureCronet.m @@ -16,6 +16,8 @@ * */ +#ifdef GRPC_COMPILE_WITH_CRONET + #import "ConfigureCronet.h" #import @@ -33,3 +35,5 @@ void configureCronet(void) { [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; }); } + +#endif diff --git a/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m b/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m index aa1af301b96..a2a79c46316 100644 --- a/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m +++ b/src/objective-c/tests/CronetTests/InteropTestsRemoteWithCronet.m @@ -22,7 +22,6 @@ #import #import -#import "../ConfigureCronet.h" #import "InteropTests.h" // The server address is derived from preprocessor macro, which is @@ -41,19 +40,12 @@ static int32_t kRemoteInteropServerOverhead = 12; @implementation InteropTestsRemoteWithCronet -+ (void)setUp { - configureCronet(); - [GRPCCall useCronetWithEngine:[Cronet getGlobalEngine]]; - - [super setUp]; -} - + (NSString *)host { return kRemoteSSLHost; } -+ (GRPCTransportId)transport { - return gGRPCCoreCronetId; ++ (BOOL)useCronet { + return YES; } - (int32_t)encodingOverhead { diff --git a/src/objective-c/tests/InteropTests/InteropTests.h b/src/objective-c/tests/InteropTests/InteropTests.h index a4adecd5415..28fcbff9695 100644 --- a/src/objective-c/tests/InteropTests/InteropTests.h +++ b/src/objective-c/tests/InteropTests/InteropTests.h @@ -48,19 +48,11 @@ - (int32_t)encodingOverhead; /** - * DEPRECATED: \a transportType is a deprecated option. Please use \a transport instead. - * * The type of transport to be used. The base implementation returns default. Subclasses should * override to appropriate settings. */ + (GRPCTransportType)transportType; -/* - * The transport to be used. The base implementation returns NULL. Subclasses should override to - * appropriate settings. - */ -+ (GRPCTransportId)transport; - /** * The root certificates to be used. The base implementation returns nil. Subclasses should override * to appropriate settings. @@ -73,4 +65,9 @@ */ + (NSString *)hostNameOverride; +/** + * Whether to use Cronet for all the v1 API tests in the test suite. + */ ++ (BOOL)useCronet; + @end diff --git a/src/objective-c/tests/InteropTests/InteropTests.m b/src/objective-c/tests/InteropTests/InteropTests.m index 21198f7bad9..a8f7db7ee93 100644 --- a/src/objective-c/tests/InteropTests/InteropTests.m +++ b/src/objective-c/tests/InteropTests/InteropTests.m @@ -20,6 +20,9 @@ #include +#ifdef GRPC_COMPILE_WITH_CRONET +#import +#endif #import #import #import @@ -35,6 +38,7 @@ #import "src/objective-c/tests/RemoteTestClient/Test.pbobjc.h" #import "src/objective-c/tests/RemoteTestClient/Test.pbrpc.h" +#import "../ConfigureCronet.h" #import "InteropTestsBlockCallbacks.h" #define TEST_TIMEOUT 32 @@ -87,8 +91,9 @@ BOOL isRemoteInteropTest(NSString *host) { - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { dispatch_queue_t queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); - return - [[GRPCInterceptor alloc] initWithInterceptorManager:interceptorManager dispatchQueue:queue]; + return [[GRPCInterceptor alloc] initWithInterceptorManager:interceptorManager + requestDispatchQueue:queue + responseDispatchQueue:queue]; } @end @@ -96,19 +101,21 @@ BOOL isRemoteInteropTest(NSString *host) { @interface HookInterceptorFactory : NSObject - (instancetype) - initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, - GRPCInterceptorManager *manager))startHook - writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook - finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook -receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - GRPCInterceptorManager *manager))receiveNextMessagesHook - responseHeaderHook:(void (^)(NSDictionary *initialMetadata, - GRPCInterceptorManager *manager))responseHeaderHook - responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook - responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, - GRPCInterceptorManager *manager))responseCloseHook - didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; +initWithRequestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue + startHook:(void (^)(GRPCRequestOptions *requestOptions, + GRPCCallOptions *callOptions, + GRPCInterceptorManager *manager))startHook + writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook + finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook + receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, + GRPCInterceptorManager *manager))receiveNextMessagesHook + responseHeaderHook:(void (^)(NSDictionary *initialMetadata, + GRPCInterceptorManager *manager))responseHeaderHook + responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook + responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, + GRPCInterceptorManager *manager))responseCloseHook + didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager; @@ -118,7 +125,8 @@ receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - (instancetype) initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager - dispatchQueue:(dispatch_queue_t)dispatchQueue + requestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook @@ -147,25 +155,29 @@ initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager void (^_responseCloseHook)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager); void (^_didWriteDataHook)(GRPCInterceptorManager *manager); - dispatch_queue_t _dispatchQueue; + dispatch_queue_t _requestDispatchQueue; + dispatch_queue_t _responseDispatchQueue; } - (instancetype) - initWithDispatchQueue:(dispatch_queue_t)dispatchQueue - startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, - GRPCInterceptorManager *manager))startHook - writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook - finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook -receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - GRPCInterceptorManager *manager))receiveNextMessagesHook - responseHeaderHook:(void (^)(NSDictionary *initialMetadata, - GRPCInterceptorManager *manager))responseHeaderHook - responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook - responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, - GRPCInterceptorManager *manager))responseCloseHook - didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { +initWithRequestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue + startHook:(void (^)(GRPCRequestOptions *requestOptions, + GRPCCallOptions *callOptions, + GRPCInterceptorManager *manager))startHook + writeDataHook:(void (^)(id data, GRPCInterceptorManager *manager))writeDataHook + finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook + receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, + GRPCInterceptorManager *manager))receiveNextMessagesHook + responseHeaderHook:(void (^)(NSDictionary *initialMetadata, + GRPCInterceptorManager *manager))responseHeaderHook + responseDataHook:(void (^)(id data, GRPCInterceptorManager *manager))responseDataHook + responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, + GRPCInterceptorManager *manager))responseCloseHook + didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { if ((self = [super init])) { - _dispatchQueue = dispatchQueue; + _requestDispatchQueue = requestDispatchQueue; + _responseDispatchQueue = responseDispatchQueue; _startHook = startHook; _writeDataHook = writeDataHook; _finishHook = finishHook; @@ -180,7 +192,8 @@ receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { return [[HookInterceptor alloc] initWithInterceptorManager:interceptorManager - dispatchQueue:_dispatchQueue + requestDispatchQueue:_requestDispatchQueue + responseDispatchQueue:_responseDispatchQueue startHook:_startHook writeDataHook:_writeDataHook finishHook:_finishHook @@ -205,16 +218,22 @@ receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); void (^_didWriteDataHook)(GRPCInterceptorManager *manager); GRPCInterceptorManager *_manager; - dispatch_queue_t _dispatchQueue; + dispatch_queue_t _requestDispatchQueue; + dispatch_queue_t _responseDispatchQueue; +} + +- (dispatch_queue_t)requestDispatchQueue { + return _requestDispatchQueue; } - (dispatch_queue_t)dispatchQueue { - return _dispatchQueue; + return _responseDispatchQueue; } - (instancetype) initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager - dispatchQueue:(dispatch_queue_t)dispatchQueue + requestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook @@ -228,7 +247,9 @@ initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { - if ((self = [super initWithInterceptorManager:interceptorManager dispatchQueue:dispatchQueue])) { + if ((self = [super initWithInterceptorManager:interceptorManager + requestDispatchQueue:requestDispatchQueue + responseDispatchQueue:responseDispatchQueue])) { _startHook = startHook; _writeDataHook = writeDataHook; _finishHook = finishHook; @@ -237,7 +258,8 @@ initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager _responseDataHook = responseDataHook; _responseCloseHook = responseCloseHook; _didWriteDataHook = didWriteDataHook; - _dispatchQueue = dispatchQueue; + _requestDispatchQueue = requestDispatchQueue; + _responseDispatchQueue = responseDispatchQueue; _manager = interceptorManager; } return self; @@ -298,7 +320,8 @@ initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager @property BOOL enabled; -- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue; +- (instancetype)initWithRequestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue; - (void)setStartHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook @@ -317,23 +340,26 @@ initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager @implementation GlobalInterceptorFactory -- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue { +- (instancetype)initWithRequestDispatchQueue:(dispatch_queue_t)requestDispatchQueue + responseDispatchQueue:(dispatch_queue_t)responseDispatchQueue { _enabled = NO; - return [super initWithDispatchQueue:dispatchQueue - startHook:nil - writeDataHook:nil - finishHook:nil - receiveNextMessagesHook:nil - responseHeaderHook:nil - responseDataHook:nil - responseCloseHook:nil - didWriteDataHook:nil]; + return [super initWithRequestDispatchQueue:requestDispatchQueue + responseDispatchQueue:responseDispatchQueue + startHook:nil + writeDataHook:nil + finishHook:nil + receiveNextMessagesHook:nil + responseHeaderHook:nil + responseDataHook:nil + responseCloseHook:nil + didWriteDataHook:nil]; } - (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager { if (_enabled) { return [[HookInterceptor alloc] initWithInterceptorManager:interceptorManager - dispatchQueue:_dispatchQueue + requestDispatchQueue:_requestDispatchQueue + responseDispatchQueue:_responseDispatchQueue startHook:_startHook writeDataHook:_writeDataHook finishHook:_finishHook @@ -399,15 +425,10 @@ static dispatch_once_t initGlobalInterceptorFactory; return 0; } -// For backwards compatibility + (GRPCTransportType)transportType { return GRPCTransportTypeChttp2BoringSSL; } -+ (GRPCTransportId)transport { - return NULL; -} - + (NSString *)PEMRootCertificates { return nil; } @@ -416,11 +437,26 @@ static dispatch_once_t initGlobalInterceptorFactory; return nil; } ++ (BOOL)useCronet { + return NO; +} + + (void)setUp { +#ifdef GRPC_COMPILE_WITH_CRONET + configureCronet(); + if ([self useCronet]) { + [GRPCCall useCronetWithEngine:[Cronet getGlobalEngine]]; + } +#endif +#ifdef GRPC_CFSTREAM + setenv(kCFStreamVarName, "1", 1); +#endif + dispatch_once(&initGlobalInterceptorFactory, ^{ dispatch_queue_t globalInterceptorQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); globalInterceptorFactory = - [[GlobalInterceptorFactory alloc] initWithDispatchQueue:globalInterceptorQueue]; + [[GlobalInterceptorFactory alloc] initWithRequestDispatchQueue:globalInterceptorQueue + responseDispatchQueue:globalInterceptorQueue]; [GRPCCall2 registerGlobalInterceptor:globalInterceptorFactory]; }); } @@ -466,9 +502,7 @@ static dispatch_once_t initGlobalInterceptorFactory; GPBEmpty *request = [GPBEmpty message]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; @@ -497,9 +531,7 @@ static dispatch_once_t initGlobalInterceptorFactory; GPBEmpty *request = [GPBEmpty message]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; @@ -576,9 +608,7 @@ static dispatch_once_t initGlobalInterceptorFactory; request.payload.body = [NSMutableData dataWithLength:271828]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; @@ -626,9 +656,7 @@ static dispatch_once_t initGlobalInterceptorFactory; request.responseStatus.code = GRPC_STATUS_CANCELLED; } GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; @@ -930,9 +958,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; @@ -984,9 +1010,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.flowControlEnabled = YES; @@ -1143,9 +1167,7 @@ static dispatch_once_t initGlobalInterceptorFactory; __block BOOL receivedResponse = NO; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = self.class.transportType; - options.transport = [[self class] transport]; options.PEMRootCertificates = self.class.PEMRootCertificates; options.hostNameOverride = [[self class] hostNameOverride]; @@ -1178,9 +1200,7 @@ static dispatch_once_t initGlobalInterceptorFactory; [self expectationWithDescription:@"Call completed."]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = self.class.transportType; - options.transport = [[self class] transport]; options.PEMRootCertificates = self.class.PEMRootCertificates; options.hostNameOverride = [[self class] hostNameOverride]; @@ -1266,47 +1286,48 @@ static dispatch_once_t initGlobalInterceptorFactory; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; } -- (void)testKeepaliveWithV2API { +#ifndef GRPC_COMPILE_WITH_CRONET +- (void)testKeepalive { XCTAssertNotNil([[self class] host]); - if ([[self class] transport] == gGRPCCoreCronetId) { - // Cronet does not support keepalive - return; - } __weak XCTestExpectation *expectation = [self expectationWithDescription:@"Keepalive"]; - NSNumber *kRequestSize = @27182; - NSNumber *kResponseSize = @31415; + [GRPCCall setKeepaliveWithInterval:1500 timeout:0 forHost:[[self class] host]]; - id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:kRequestSize - requestedResponseSize:kResponseSize]; - GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; - options.PEMRootCertificates = [[self class] PEMRootCertificates]; - options.hostNameOverride = [[self class] hostNameOverride]; - options.keepaliveInterval = 1.5; - options.keepaliveTimeout = 0; + NSArray *requests = @[ @27182, @8 ]; + NSArray *responses = @[ @31415, @9 ]; - __block GRPCStreamingProtoCall *call = [_service - fullDuplexCallWithResponseHandler: - [[InteropTestsBlockCallbacks alloc] - initWithInitialMetadataCallback:nil - messageCallback:nil - closeCallback:^(NSDictionary *trailingMetadata, NSError *error) { - XCTAssertNotNil(error); - XCTAssertEqual( - error.code, GRPC_STATUS_UNAVAILABLE, - @"Received status %ld instead of UNAVAILABLE (14).", - error.code); - [expectation fulfill]; - }] - callOptions:options]; - [call writeMessage:request]; - [call start]; + GRXBufferedPipe *requestsBuffer = [[GRXBufferedPipe alloc] init]; + + __block int index = 0; + + id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] + requestedResponseSize:responses[index]]; + [requestsBuffer writeValue:request]; + + [_service + fullDuplexCallWithRequestsWriter:requestsBuffer + eventHandler:^(BOOL done, RMTStreamingOutputCallResponse *response, + NSError *error) { + if (index == 0) { + XCTAssertNil(error, @"Finished with unexpected error: %@", error); + XCTAssertTrue(response, @"Event handler called without an event."); + XCTAssertFalse(done); + index++; + } else { + // Keepalive should kick after 1s elapsed and fails the call. + XCTAssertNotNil(error); + XCTAssertEqual(error.code, GRPC_STATUS_UNAVAILABLE); + XCTAssertEqualObjects( + error.localizedDescription, @"keepalive watchdog timeout", + @"Unexpected failure that is not keepalive watchdog timeout."); + XCTAssertTrue(done); + [expectation fulfill]; + } + }]; [self waitForExpectationsWithTimeout:TEST_TIMEOUT handler:nil]; - [call finish]; } +#endif - (void)testDefaultInterceptor { XCTAssertNotNil([[self class] host]); @@ -1321,9 +1342,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init] ]; @@ -1378,7 +1397,8 @@ static dispatch_once_t initGlobalInterceptorFactory; __block NSUInteger responseCloseCount = 0; __block NSUInteger didWriteDataCount = 0; id factory = [[HookInterceptorFactory alloc] - initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + initWithRequestDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + responseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { startCount++; @@ -1426,9 +1446,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.flowControlEnabled = YES; @@ -1506,7 +1524,8 @@ static dispatch_once_t initGlobalInterceptorFactory; __block NSUInteger responseDataCount = 0; __block NSUInteger responseCloseCount = 0; id factory = [[HookInterceptorFactory alloc] - initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + initWithRequestDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + responseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { startCount++; @@ -1533,7 +1552,6 @@ static dispatch_once_t initGlobalInterceptorFactory; // finish must happen after the hijacking, so directly reply with a close [manager forwardPreviousInterceptorCloseWithTrailingMetadata:@{@"grpc-status" : @"0"} error:nil]; - [manager shutDown]; } receiveNextMessagesHook:nil responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { @@ -1560,9 +1578,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init], factory ]; @@ -1671,9 +1687,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.flowControlEnabled = YES; @@ -1728,15 +1742,16 @@ static dispatch_once_t initGlobalInterceptorFactory; - (void)testConflictingGlobalInterceptors { id factory = [[HookInterceptorFactory alloc] - initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) - startHook:nil - writeDataHook:nil - finishHook:nil - receiveNextMessagesHook:nil - responseHeaderHook:nil - responseDataHook:nil - responseCloseHook:nil - didWriteDataHook:nil]; + initWithRequestDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + responseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + startHook:nil + writeDataHook:nil + finishHook:nil + receiveNextMessagesHook:nil + responseHeaderHook:nil + responseDataHook:nil + responseCloseHook:nil + didWriteDataHook:nil]; @try { [GRPCCall2 registerGlobalInterceptor:factory]; XCTFail(@"Did not receive an exception when registering global interceptor the second time"); @@ -1760,7 +1775,8 @@ static dispatch_once_t initGlobalInterceptorFactory; __block NSUInteger didWriteDataCount = 0; id factory = [[HookInterceptorFactory alloc] - initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + initWithRequestDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) + responseDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { startCount++; @@ -1856,9 +1872,7 @@ static dispatch_once_t initGlobalInterceptorFactory; id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] requestedResponseSize:responses[index]]; GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; - // For backwards compatibility options.transportType = [[self class] transportType]; - options.transport = [[self class] transport]; options.PEMRootCertificates = [[self class] PEMRootCertificates]; options.hostNameOverride = [[self class] hostNameOverride]; options.flowControlEnabled = YES; diff --git a/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m b/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m index 2e638099e1e..a9c69183332 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m +++ b/src/objective-c/tests/InteropTests/InteropTestsLocalCleartext.m @@ -17,7 +17,6 @@ */ #import -#import #import #import "InteropTests.h" @@ -61,8 +60,8 @@ static int32_t kLocalInteropServerOverhead = 10; [GRPCCall useInsecureConnectionsForHost:kLocalCleartextHost]; } -+ (GRPCTransportId)transport { - return GRPCDefaultTransportImplList.core_insecure; ++ (GRPCTransportType)transportType { + return GRPCTransportTypeInsecure; } @end diff --git a/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m b/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m index 30d8f4c34af..e8222f602f4 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m +++ b/src/objective-c/tests/InteropTests/InteropTestsLocalSSL.m @@ -17,7 +17,6 @@ */ #import -#import #import #import "InteropTests.h" @@ -57,8 +56,8 @@ static int32_t kLocalInteropServerOverhead = 10; return kLocalInteropServerOverhead; // bytes } -+ (GRPCTransportId)transport { - return GRPCDefaultTransportImplList.core_secure; ++ (GRPCTransportType)transportType { + return GRPCTransportTypeChttp2BoringSSL; } - (void)setUp { diff --git a/src/objective-c/tests/InteropTests/InteropTestsMultipleChannels.m b/src/objective-c/tests/InteropTests/InteropTestsMultipleChannels.m index dc48391cbcc..98893a466bd 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsMultipleChannels.m +++ b/src/objective-c/tests/InteropTests/InteropTestsMultipleChannels.m @@ -18,8 +18,9 @@ #import +#ifdef GRPC_COMPILE_WITH_CRONET #import -#import +#endif #import #import "src/objective-c/tests/RemoteTestClient/Messages.pbobjc.h" #import "src/objective-c/tests/RemoteTestClient/Test.pbobjc.h" diff --git a/src/objective-c/tests/InteropTests/InteropTestsRemote.m b/src/objective-c/tests/InteropTests/InteropTestsRemote.m index 2dd8f0aed89..c1cd9b81efc 100644 --- a/src/objective-c/tests/InteropTests/InteropTestsRemote.m +++ b/src/objective-c/tests/InteropTests/InteropTestsRemote.m @@ -53,8 +53,14 @@ static int32_t kRemoteInteropServerOverhead = 12; return kRemoteInteropServerOverhead; // bytes } +#ifdef GRPC_COMPILE_WITH_CRONET ++ (GRPCTransportType)transportType { + return GRPCTransportTypeCronet; +} +#else + (GRPCTransportType)transportType { return GRPCTransportTypeChttp2BoringSSL; } +#endif @end diff --git a/src/objective-c/tests/Podfile b/src/objective-c/tests/Podfile index c83e8861e93..c2297aa00fd 100644 --- a/src/objective-c/tests/Podfile +++ b/src/objective-c/tests/Podfile @@ -30,23 +30,23 @@ target 'MacTests' do grpc_deps end +target 'UnitTests' do + platform :ios, '8.0' + grpc_deps +end + %w( - UnitTests InteropTests + CronetTests ).each do |target_name| target target_name do platform :ios, '8.0' grpc_deps - end -end -target 'CronetTests' do - platform :ios, '8.0' - grpc_deps - - pod 'gRPC/GRPCCoreCronet', :path => GRPC_LOCAL_SRC - pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" - pod 'gRPC-Core/Tests', :path => GRPC_LOCAL_SRC, :inhibit_warnings => true + pod 'gRPC-Core/Cronet-Implementation', :path => GRPC_LOCAL_SRC + pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" + pod 'gRPC-Core/Tests', :path => GRPC_LOCAL_SRC, :inhibit_warnings => true + end end # gRPC-Core.podspec needs to be modified to be successfully used for local development. A Podfile's @@ -103,7 +103,7 @@ post_install do |installer| # the test target 'InteropTestsRemoteWithCronet' # Activate GRPCCall+InternalTests functions for the dedicated build configuration 'Test', which will # be used by all test targets using it. - if /gRPC(-macOS|-iOS|-tvOS|\.|-[0-9a-f])/.match(target.name) + if /gRPC-(mac|i|tv)OS/.match(target.name) target.build_configurations.each do |config| if config.name == 'Cronet' config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = '$(inherited) COCOAPODS=1 GRPC_COMPILE_WITH_CRONET=1 GRPC_TEST_OBJC=1' @@ -114,7 +114,7 @@ post_install do |installer| end # Enable NSAssert on gRPC - if /(gRPC|ProtoRPC|RxLibrary)/.match(target.name) + if /(gRPC|ProtoRPC|RxLibrary)-(mac|i|tv)OS/.match(target.name) target.build_configurations.each do |config| if config.name != 'Release' config.build_settings['ENABLE_NS_ASSERTIONS'] = 'YES' diff --git a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj index 6cb9f5560b9..a88838fdc8b 100644 --- a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj +++ b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj @@ -8,14 +8,15 @@ /* Begin PBXBuildFile section */ 5E0282E9215AA697007AC99D /* NSErrorUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E0282E8215AA697007AC99D /* NSErrorUnitTests.m */; }; - 5E08D07023021E3B006D76EA /* InteropTestsMultipleChannels.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487722778226006656AD /* InteropTestsMultipleChannels.m */; }; 5E3F14842278B461007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; }; 5E3F14852278BF5D007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; }; 5E3F14862278BFFF007C6D90 /* InteropTestsBlockCallbacks.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F14832278B461007C6D90 /* InteropTestsBlockCallbacks.m */; }; 5E3F148D22792856007C6D90 /* ConfigureCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F1487227918AA007C6D90 /* ConfigureCronet.m */; }; + 5E3F148E22792AF5007C6D90 /* ConfigureCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E3F1487227918AA007C6D90 /* ConfigureCronet.m */; }; 5E7F486422775B37006656AD /* InteropTestsRemoteWithCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */; }; 5E7F486522775B41006656AD /* CronetUnitTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5EAD6D261E27047400002378 /* CronetUnitTests.mm */; }; 5E7F486E22778086006656AD /* CoreCronetEnd2EndTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F486D22778086006656AD /* CoreCronetEnd2EndTests.mm */; }; + 5E7F487922778226006656AD /* InteropTestsMultipleChannels.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487722778226006656AD /* InteropTestsMultipleChannels.m */; }; 5E7F487D22778256006656AD /* ChannelPoolTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487B22778256006656AD /* ChannelPoolTest.m */; }; 5E7F487E22778256006656AD /* ChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487C22778256006656AD /* ChannelTests.m */; }; 5E7F4880227782C1006656AD /* APIv2Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E7F487F227782C1006656AD /* APIv2Tests.m */; }; @@ -33,7 +34,6 @@ 5EA4770322736178000F72FC /* InteropTestsLocalSSL.m in Sources */ = {isa = PBXBuildFile; fileRef = 63E240CD1B6C4E2B005F3B0E /* InteropTestsLocalSSL.m */; }; 5EA477042273617B000F72FC /* InteropTestsLocalCleartext.m in Sources */ = {isa = PBXBuildFile; fileRef = 63715F551B780C020029CB0B /* InteropTestsLocalCleartext.m */; }; 5EA4770522736AC4000F72FC /* TestCertificates.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */; }; - 5ECFED8623030DCC00626501 /* TestCertificates.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */; }; 65EB19E418B39A8374D407BB /* libPods-CronetTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1B1511C20E16A8422B58D61A /* libPods-CronetTests.a */; }; 903163C7FE885838580AEC7A /* libPods-InteropTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D457AD9797664CFA191C3280 /* libPods-InteropTests.a */; }; 953CD2942A3A6D6CE695BE87 /* libPods-MacTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 276873A05AC5479B60DF6079 /* libPods-MacTests.a */; }; @@ -515,6 +515,7 @@ 5EA476F12272816A000F72FC /* Frameworks */, 5EA476F22272816A000F72FC /* Resources */, D11CB94CF56A1E53760D29D8 /* [CP] Copy Pods Resources */, + 0FEFD5FC6B323AC95549AE4A /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -629,7 +630,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5ECFED8623030DCC00626501 /* TestCertificates.bundle in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -678,6 +678,24 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + 0FEFD5FC6B323AC95549AE4A /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-InteropTests/Pods-InteropTests-frameworks.sh", + "${PODS_ROOT}/CronetFramework/Cronet.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Cronet.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-InteropTests/Pods-InteropTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 292EA42A76AC7933A37235FD /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -703,7 +721,7 @@ ); inputPaths = ( "${PODS_ROOT}/Target Support Files/Pods-CronetTests/Pods-CronetTests-resources.sh", - "${PODS_CONFIGURATION_BUILD_DIR}/gRPC.default-GRPCCoreCronet/gRPCCertificates.bundle", + "${PODS_CONFIGURATION_BUILD_DIR}/gRPC-iOS/gRPCCertificates.bundle", ); name = "[CP] Copy Pods Resources"; outputPaths = ( @@ -880,7 +898,6 @@ files = ( 5E3F14852278BF5D007C6D90 /* InteropTestsBlockCallbacks.m in Sources */, 5E3F148D22792856007C6D90 /* ConfigureCronet.m in Sources */, - 5E08D07023021E3B006D76EA /* InteropTestsMultipleChannels.m in Sources */, 5E7F486E22778086006656AD /* CoreCronetEnd2EndTests.mm in Sources */, 5E7F488522778A88006656AD /* InteropTests.m in Sources */, 5E7F486422775B37006656AD /* InteropTestsRemoteWithCronet.m in Sources */, @@ -893,7 +910,9 @@ buildActionMask = 2147483647; files = ( 5E3F14842278B461007C6D90 /* InteropTestsBlockCallbacks.m in Sources */, + 5E3F148E22792AF5007C6D90 /* ConfigureCronet.m in Sources */, 5E7F488922778B04006656AD /* InteropTestsRemote.m in Sources */, + 5E7F487922778226006656AD /* InteropTestsMultipleChannels.m in Sources */, 5EA477042273617B000F72FC /* InteropTestsLocalCleartext.m in Sources */, 5EA4770322736178000F72FC /* InteropTestsLocalSSL.m in Sources */, 5E7F488422778A88006656AD /* InteropTests.m in Sources */, diff --git a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/InteropTests.xcscheme b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/InteropTests.xcscheme index cbde360a338..adb3c366af2 100644 --- a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/InteropTests.xcscheme +++ b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/InteropTests.xcscheme @@ -23,7 +23,7 @@ @@ -48,7 +48,7 @@ + buildConfiguration = "Cronet"> -#import "../../GRPCClient/private/GRPCCore/GRPCChannel.h" -#import "../../GRPCClient/private/GRPCCore/GRPCChannelPool+Test.h" -#import "../../GRPCClient/private/GRPCCore/GRPCCompletionQueue.h" +#import "../../GRPCClient/private/GRPCChannel.h" +#import "../../GRPCClient/private/GRPCChannelPool+Test.h" +#import "../../GRPCClient/private/GRPCCompletionQueue.h" #define TEST_TIMEOUT 32 diff --git a/src/objective-c/tests/UnitTests/ChannelTests.m b/src/objective-c/tests/UnitTests/ChannelTests.m index 1ed0f16ecaf..df78e8b1162 100644 --- a/src/objective-c/tests/UnitTests/ChannelTests.m +++ b/src/objective-c/tests/UnitTests/ChannelTests.m @@ -19,11 +19,11 @@ #import #import "../../GRPCClient/GRPCCallOptions.h" -#import "../../GRPCClient/private/GRPCCore/GRPCChannel.h" -#import "../../GRPCClient/private/GRPCCore/GRPCChannelPool+Test.h" -#import "../../GRPCClient/private/GRPCCore/GRPCChannelPool.h" -#import "../../GRPCClient/private/GRPCCore/GRPCCompletionQueue.h" -#import "../../GRPCClient/private/GRPCCore/GRPCWrappedCall.h" +#import "../../GRPCClient/private/GRPCChannel.h" +#import "../../GRPCClient/private/GRPCChannelPool+Test.h" +#import "../../GRPCClient/private/GRPCChannelPool.h" +#import "../../GRPCClient/private/GRPCCompletionQueue.h" +#import "../../GRPCClient/private/GRPCWrappedCall.h" static NSString *kDummyHost = @"dummy.host"; static NSString *kDummyPath = @"/dummy/path"; diff --git a/src/objective-c/tests/UnitTests/NSErrorUnitTests.m b/src/objective-c/tests/UnitTests/NSErrorUnitTests.m index 74e5794c480..8a4f03a4460 100644 --- a/src/objective-c/tests/UnitTests/NSErrorUnitTests.m +++ b/src/objective-c/tests/UnitTests/NSErrorUnitTests.m @@ -20,7 +20,7 @@ #import -#import "../../GRPCClient/private/GRPCCore/NSError+GRPC.h" +#import "../../GRPCClient/private/NSError+GRPC.h" @interface NSErrorUnitTests : XCTestCase diff --git a/templates/gRPC-ProtoRPC.podspec.template b/templates/gRPC-ProtoRPC.podspec.template index e94f149ee4a..457d2988036 100644 --- a/templates/gRPC-ProtoRPC.podspec.template +++ b/templates/gRPC-ProtoRPC.podspec.template @@ -44,40 +44,22 @@ s.module_name = name s.header_dir = name - s.default_subspec = 'Main', 'Legacy', 'Legacy-Header' + src_dir = 'src/objective-c/ProtoRPC' - s.subspec 'Legacy-Header' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.public_header_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.h" - ss.source_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.h" - end + s.default_subspec = 'Main' s.subspec 'Main' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.dependency "#{s.name}/Legacy-Header", version - ss.dependency 'gRPC/Interface', version - ss.dependency 'Protobuf', '~> 3.0' - - ss.source_files = "src/objective-c/ProtoRPC/ProtoMethod.{h,m}", - "src/objective-c/ProtoRPC/ProtoRPC.{h,m}", - "src/objective-c/ProtoRPC/ProtoService.{h,m}" - end - - s.subspec 'Legacy' do |ss| - ss.header_mappings_dir = "src/objective-c/ProtoRPC" - ss.dependency "#{s.name}/Main", version - ss.dependency "#{s.name}/Legacy-Header", version - ss.dependency 'gRPC/GRPCCore', version + ss.header_mappings_dir = "#{src_dir}" + ss.dependency 'gRPC', version ss.dependency 'gRPC-RxLibrary', version ss.dependency 'Protobuf', '~> 3.0' - ss.source_files = "src/objective-c/ProtoRPC/ProtoRPCLegacy.m", - "src/objective-c/ProtoRPC/ProtoServiceLegacy.m" + ss.source_files = "#{src_dir}/*.{h,m}" end # CFStream is now default. Leaving this subspec only for compatibility purpose. s.subspec 'CFStream' do |ss| - ss.dependency "#{s.name}/Legacy", version + ss.dependency "#{s.name}/Main", version end s.pod_target_xcconfig = { diff --git a/templates/gRPC-RxLibrary.podspec.template b/templates/gRPC-RxLibrary.podspec.template index 772265dadda..9389c5ecd8d 100644 --- a/templates/gRPC-RxLibrary.podspec.template +++ b/templates/gRPC-RxLibrary.podspec.template @@ -44,23 +44,6 @@ s.module_name = name s.header_dir = name - s.default_subspec = 'Interface', 'Implementation' - - src_dir = 'src/objective-c/RxLibrary' - s.subspec 'Interface' do |ss| - ss.header_mappings_dir = "#{src_dir}" - ss.source_files = "#{src_dir}/*.h" - ss.public_header_files = "#{src_dir}/*.h" - end - - s.subspec 'Implementation' do |ss| - ss.header_mappings_dir = "#{src_dir}" - ss.source_files = "#{src_dir}/*.m", "#{src_dir}/**/*.{h,m}" - ss.private_header_files = "#{src_dir}/**/*.h" - - ss.dependency "#{s.name}/Interface" - end - src_dir = 'src/objective-c/RxLibrary' s.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}" s.private_header_files = "#{src_dir}/private/*.h" diff --git a/templates/gRPC.podspec.template b/templates/gRPC.podspec.template index e705edc1748..8cb380ede03 100644 --- a/templates/gRPC.podspec.template +++ b/templates/gRPC.podspec.template @@ -43,7 +43,13 @@ s.module_name = name s.header_dir = name - s.default_subspec = 'Interface', 'GRPCCore', 'Interface-Legacy' + src_dir = 'src/objective-c/GRPCClient' + + s.dependency 'gRPC-RxLibrary', version + s.default_subspec = 'Main' + + # Certificates, to be able to establish TLS connections: + s.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] } s.pod_target_xcconfig = { # This is needed by all pods that depend on gRPC-RxLibrary: @@ -51,103 +57,29 @@ 'CLANG_WARN_STRICT_PROTOTYPES' => 'NO', } - s.subspec 'Interface-Legacy' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "src/objective-c/GRPCClient/GRPCCallLegacy.h", - "src/objective-c/GRPCClient/GRPCTypes.h" - - ss.source_files = "GRPCClient/GRPCCall+ChannelArg.h", - "GRPCClient/GRPCCall+ChannelCredentials.h", - "GRPCClient/GRPCCall+Cronet.h", - "GRPCClient/GRPCCall+OAuth2.h", - "GRPCClient/GRPCCall+Tests.h", - "src/objective-c/GRPCClient/GRPCCallLegacy.h", - "src/objective-c/GRPCClient/GRPCTypes.h" - ss.dependency "gRPC-RxLibrary/Interface", version - end + s.subspec 'Main' do |ss| + ss.header_mappings_dir = "#{src_dir}" - s.subspec 'Interface' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = 'src/objective-c/GRPCClient/GRPCCall.h', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.h', - 'src/objective-c/GRPCClient/GRPCCallOptions.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.h', - 'src/objective-c/GRPCClient/GRPCTransport.h', - 'src/objective-c/GRPCClient/GRPCDispatchable.h', - 'src/objective-c/GRPCClient/version.h' - - ss.source_files = 'src/objective-c/GRPCClient/GRPCCall.h', - 'src/objective-c/GRPCClient/GRPCCall.m', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.h', - 'src/objective-c/GRPCClient/GRPCCall+Interceptor.m', - 'src/objective-c/GRPCClient/GRPCCallOptions.h', - 'src/objective-c/GRPCClient/GRPCCallOptions.m', - 'src/objective-c/GRPCClient/GRPCDispatchable.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.h', - 'src/objective-c/GRPCClient/GRPCInterceptor.m', - 'src/objective-c/GRPCClient/GRPCTransport.h', - 'src/objective-c/GRPCClient/GRPCTransport.m', - 'src/objective-c/GRPCClient/internal/*.h', - 'src/objective-c/GRPCClient/private/GRPCTransport+Private.h', - 'src/objective-c/GRPCClient/private/GRPCTransport+Private.m', - 'src/objective-c/GRPCClient/version.h' - - ss.dependency "#{s.name}/Interface-Legacy", version - end + ss.source_files = "#{src_dir}/*.{h,m}", "#{src_dir}/**/*.{h,m}" + ss.exclude_files = "#{src_dir}/GRPCCall+GID.{h,m}" + ss.private_header_files = "#{src_dir}/private/*.h", "#{src_dir}/internal/*.h" - s.subspec 'GRPCCore' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.public_header_files = 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.h', - 'src/objective-c/GRPCClient/GRPCCall+Tests.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.h', - 'src/objective-c/GRPCClient/internal_testing/*.h' - ss.private_header_files = 'src/objective-c/GRPCClient/private/GRPCCore/*.h' - ss.source_files = 'src/objective-c/GRPCClient/internal_testing/*.{h,m}', - 'src/objective-c/GRPCClient/private/GRPCCore/*.{h,m}', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelArg.m', - 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.h', - 'src/objective-c/GRPCClient/GRPCCall+ChannelCredentials.m', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.m', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.h', - 'src/objective-c/GRPCClient/GRPCCall+OAuth2.m', - 'src/objective-c/GRPCClient/GRPCCall+Tests.h', - 'src/objective-c/GRPCClient/GRPCCall+Tests.m', - 'src/objective-c/GRPCClient/GRPCCallLegacy.m' - - # Certificates, to be able to establish TLS connections: - ss.resource_bundles = { 'gRPCCertificates' => ['etc/roots.pem'] } - - ss.dependency "#{s.name}/Interface-Legacy", version - ss.dependency "#{s.name}/Interface", version ss.dependency 'gRPC-Core', version - ss.dependency 'gRPC-RxLibrary', version - end - - s.subspec 'GRPCCoreCronet' do |ss| - ss.header_mappings_dir = 'src/objective-c/GRPCClient' - - ss.source_files = 'src/objective-c/GRPCClient/GRPCCall+Cronet.h', - 'src/objective-c/GRPCClient/GRPCCall+Cronet.m', - 'src/objective-c/GRPCClient/private/GRPCCore/GRPCCoreCronet/*.{h,m}' - ss.dependency "#{s.name}/GRPCCore", version - ss.dependency 'gRPC-Core/Cronet-Implementation', version - ss.dependency 'CronetFramework' end # CFStream is now default. Leaving this subspec only for compatibility purpose. s.subspec 'CFStream' do |ss| - ss.dependency "#{s.name}/GRPCCore", version + ss.dependency "#{s.name}/Main", version + end + + s.subspec 'GID' do |ss| + ss.ios.deployment_target = '7.0' + + ss.header_mappings_dir = "#{src_dir}" + + ss.source_files = "#{src_dir}/GRPCCall+GID.{h,m}" + + ss.dependency "#{s.name}/Main", version + ss.dependency 'Google/SignIn' end end diff --git a/templates/src/objective-c/GRPCClient/version.h.template b/templates/src/objective-c/GRPCClient/private/version.h.template similarity index 100% rename from templates/src/objective-c/GRPCClient/version.h.template rename to templates/src/objective-c/GRPCClient/private/version.h.template From a1ca6a099d90aa0ff8002b75eeee00119d69f4f0 Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Wed, 28 Aug 2019 10:07:18 -0700 Subject: [PATCH 55/57] Refactor response building in xds test --- test/cpp/end2end/xds_end2end_test.cc | 390 ++++++++++++++------------- 1 file changed, 203 insertions(+), 187 deletions(-) diff --git a/test/cpp/end2end/xds_end2end_test.cc b/test/cpp/end2end/xds_end2end_test.cc index 480680c9a32..1c073de1b12 100644 --- a/test/cpp/end2end/xds_end2end_test.cc +++ b/test/cpp/end2end/xds_end2end_test.cc @@ -96,7 +96,6 @@ constexpr char kEdsTypeUrl[] = "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment"; constexpr char kDefaultLocalityRegion[] = "xds_default_locality_region"; constexpr char kDefaultLocalityZone[] = "xds_default_locality_zone"; -constexpr char kDefaultLocalitySubzone[] = "xds_default_locality_subzone"; constexpr char kLbDropType[] = "lb"; constexpr char kThrottleDropType[] = "throttle"; constexpr int kDefaultLocalityWeight = 3; @@ -260,6 +259,31 @@ class ClientStats { class EdsServiceImpl : public EdsService { public: + struct ResponseArgs { + struct Locality { + Locality(const grpc::string& sub_zone, std::vector ports, + int lb_weight = kDefaultLocalityWeight, int priority = 0) + : sub_zone(std::move(sub_zone)), + ports(std::move(ports)), + lb_weight(lb_weight), + priority(priority) {} + + const grpc::string sub_zone; + std::vector ports; + int lb_weight; + int priority; + }; + + ResponseArgs() = default; + explicit ResponseArgs(std::vector locality_list) + : locality_list(std::move(locality_list)) {} + + std::vector locality_list; + std::map drop_categories; + FractionalPercent::DenominatorType drop_denominator = + FractionalPercent::MILLION; + }; + using Stream = ServerReaderWriter; using ResponseDelayPair = std::pair; @@ -317,47 +341,35 @@ class EdsServiceImpl : public EdsService { gpr_log(GPR_INFO, "LB[%p]: shut down", this); } - // TODO(juanlishen): Put the args into a struct. - static DiscoveryResponse BuildResponse( - const std::vector>& backend_ports, - const std::vector& lb_weights = {}, - size_t first_locality_name_index = 0, - const std::map& drop_categories = {}, - const FractionalPercent::DenominatorType denominator = - FractionalPercent::MILLION) { + static DiscoveryResponse BuildResponse(const ResponseArgs& args) { ClusterLoadAssignment assignment; assignment.set_cluster_name("service name"); - for (size_t i = 0; i < backend_ports.size(); ++i) { + for (const auto& locality : args.locality_list) { auto* endpoints = assignment.add_endpoints(); - const int lb_weight = - lb_weights.empty() ? kDefaultLocalityWeight : lb_weights[i]; - endpoints->mutable_load_balancing_weight()->set_value(lb_weight); - endpoints->set_priority(0); + endpoints->mutable_load_balancing_weight()->set_value(locality.lb_weight); + endpoints->set_priority(locality.priority); endpoints->mutable_locality()->set_region(kDefaultLocalityRegion); endpoints->mutable_locality()->set_zone(kDefaultLocalityZone); - std::ostringstream sub_zone; - sub_zone << kDefaultLocalitySubzone << '_' - << first_locality_name_index + i; - endpoints->mutable_locality()->set_sub_zone(sub_zone.str()); - for (const int& backend_port : backend_ports[i]) { + endpoints->mutable_locality()->set_sub_zone(locality.sub_zone); + for (const int& port : locality.ports) { auto* lb_endpoints = endpoints->add_lb_endpoints(); auto* endpoint = lb_endpoints->mutable_endpoint(); auto* address = endpoint->mutable_address(); auto* socket_address = address->mutable_socket_address(); socket_address->set_address("127.0.0.1"); - socket_address->set_port_value(backend_port); + socket_address->set_port_value(port); } } - if (!drop_categories.empty()) { + if (!args.drop_categories.empty()) { auto* policy = assignment.mutable_policy(); - for (const auto& p : drop_categories) { + for (const auto& p : args.drop_categories) { const grpc::string& name = p.first; const uint32_t parts_per_million = p.second; auto* drop_overload = policy->add_drop_overloads(); drop_overload->set_category(name); auto* drop_percentage = drop_overload->mutable_drop_percentage(); drop_percentage->set_numerator(parts_per_million); - drop_percentage->set_denominator(denominator); + drop_percentage->set_denominator(args.drop_denominator); } } DiscoveryResponse response; @@ -729,24 +741,6 @@ class XdsEnd2endTest : public ::testing::Test { return backend_ports; } - const std::vector> GetBackendPortsInGroups( - size_t start_index = 0, size_t stop_index = 0, - size_t num_group = 1) const { - if (stop_index == 0) stop_index = backends_.size(); - size_t group_size = (stop_index - start_index) / num_group; - std::vector> backend_ports; - for (size_t i = 0; i < num_group; ++i) { - backend_ports.emplace_back(); - size_t group_start = group_size * i + start_index; - size_t group_stop = - i == num_group - 1 ? stop_index : group_start + group_size; - for (size_t j = group_start; j < group_stop; ++j) { - backend_ports[i].push_back(backends_[j]->port()); - } - } - return backend_ports; - } - void ScheduleResponseForBalancer(size_t i, const DiscoveryResponse& response, int delay_ms) { balancers_[i]->eds_service()->add_response(response, delay_ms); @@ -938,8 +932,10 @@ TEST_F(SingleBalancerTest, Vanilla) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); const size_t kNumRpcsPerAddress = 100; - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse(GetBackendPortsInGroups()), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Make sure that trying to connect works without a call. channel_->GetState(true /* try_to_connect */); // We need to wait for all backends to come online. @@ -962,17 +958,18 @@ TEST_F(SingleBalancerTest, SameBackendListedMultipleTimes) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); // Same backend listed twice. - std::vector ports; - ports.push_back(backends_[0]->port()); - ports.push_back(backends_[0]->port()); + std::vector ports(2, backends_[0]->port()); + EdsServiceImpl::ResponseArgs args({ + {"locality0", ports}, + }); const size_t kNumRpcsPerAddress = 10; - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse({ports}), 0); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // We need to wait for the backend to come online. WaitForBackend(0); // Send kNumRpcsPerAddress RPCs per server. CheckRpcSendOk(kNumRpcsPerAddress * ports.size()); // Backend should have gotten 20 requests. - EXPECT_EQ(kNumRpcsPerAddress * 2, + EXPECT_EQ(kNumRpcsPerAddress * ports.size(), backends_[0]->backend_service()->request_count()); // And they should have come from a single client port, because of // subchannel sharing. @@ -985,8 +982,10 @@ TEST_F(SingleBalancerTest, SecureNaming) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannel({balancers_[0]->port()}); const size_t kNumRpcsPerAddress = 100; - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse(GetBackendPortsInGroups()), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Make sure that trying to connect works without a call. channel_->GetState(true /* try_to_connect */); // We need to wait for all backends to come online. @@ -1031,11 +1030,17 @@ TEST_F(SingleBalancerTest, InitiallyEmptyServerlist) { const int kServerlistDelayMs = 500 * grpc_test_slowdown_factor(); const int kCallDeadlineMs = kServerlistDelayMs * 2; // First response is an empty serverlist, sent right away. - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse({{}}), 0); - // Send non-empty serverlist only after kServerlistDelayMs - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse(GetBackendPortsInGroups()), - kServerlistDelayMs); + EdsServiceImpl::ResponseArgs::Locality empty_locality("locality0", {}); + EdsServiceImpl::ResponseArgs args({ + empty_locality, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + // Send non-empty serverlist only after kServerlistDelayMs. + args = EdsServiceImpl::ResponseArgs({ + {"locality0", GetBackendPorts()}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), + kServerlistDelayMs); const auto t0 = system_clock::now(); // Client will block: LB will initially send empty serverlist. CheckRpcSendOk(1, kCallDeadlineMs, true /* wait_for_ready */); @@ -1061,7 +1066,10 @@ TEST_F(SingleBalancerTest, AllServersUnreachableFailFast) { for (size_t i = 0; i < kNumUnreachableServers; ++i) { ports.push_back(grpc_pick_unused_port_or_die()); } - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse({ports}), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", ports}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); const Status status = SendRpc(); // The error shouldn't be DEADLINE_EXCEEDED. EXPECT_EQ(StatusCode::UNAVAILABLE, status.error_code()); @@ -1082,11 +1090,11 @@ TEST_F(SingleBalancerTest, LocalityMapWeightedRoundRobin) { const double kLocalityWeightRate1 = static_cast(kLocalityWeight1) / kTotalLocalityWeight; // EDS response contains 2 localities, each of which contains 1 backend. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups(0, 2, 2), - {kLocalityWeight0, kLocalityWeight1}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts(0, 1), kLocalityWeight0}, + {"locality1", GetBackendPorts(1, 2), kLocalityWeight1}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Wait for both backends to be ready. WaitForAllBackends(1, 0, 2); // Send kNumRpcs RPCs. @@ -1118,14 +1126,19 @@ TEST_F(SingleBalancerTest, LocalityMapStressTest) { const size_t kNumLocalities = 100; // The first EDS response contains kNumLocalities localities, each of which // contains backend 0. - const std::vector> locality_list_0(kNumLocalities, - {backends_[0]->port()}); + EdsServiceImpl::ResponseArgs args; + for (size_t i = 0; i < kNumLocalities; ++i) { + grpc::string name = "locality" + std::to_string(i); + EdsServiceImpl::ResponseArgs::Locality locality(name, + {backends_[0]->port()}); + args.locality_list.emplace_back(std::move(locality)); + } + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // The second EDS response contains 1 locality, which contains backend 1. - const std::vector> locality_list_1 = - GetBackendPortsInGroups(1, 2); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(locality_list_0), - 0); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(locality_list_1), + args = EdsServiceImpl::ResponseArgs({ + {"locality0", GetBackendPorts(1, 2)}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 60 * 1000); // Wait until backend 0 is ready, before which kNumLocalities localities are // received and handled by the xds policy. @@ -1162,20 +1175,18 @@ TEST_F(SingleBalancerTest, LocalityMapUpdate) { for (int weight : kLocalityWeights1) { locality_weight_rate_1.push_back(weight / kTotalLocalityWeight1); } - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(0 /*start_index*/, 3 /*stop_index*/, - 3 /*num_group*/), - kLocalityWeights0), - 0); - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(1 /*start_index*/, 4 /*stop_index*/, - 3 /*num_group*/), - kLocalityWeights1, 1 /*first_locality_name_index*/), - 5000); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts(0, 1), 2}, + {"locality1", GetBackendPorts(1, 2), 3}, + {"locality2", GetBackendPorts(2, 3), 4}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality1", GetBackendPorts(1, 2), 3}, + {"locality2", GetBackendPorts(2, 3), 2}, + {"locality3", GetBackendPorts(3, 4), 6}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 5000); // Wait for the first 3 backends to be ready. WaitForAllBackends(1, 0, 3); gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); @@ -1244,13 +1255,12 @@ TEST_F(SingleBalancerTest, Drop) { const double KDropRateForLbAndThrottle = kDropRateForLb + (1 - kDropRateForLb) * kDropRateForThrottle; // The EDS response contains two drop categories. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerMillionForLb}, - {kThrottleDropType, kDropPerMillionForThrottle}}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, + {kThrottleDropType, kDropPerMillionForThrottle}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -1286,12 +1296,12 @@ TEST_F(SingleBalancerTest, DropPerHundred) { const uint32_t kDropPerHundredForLb = 10; const double kDropRateForLb = kDropPerHundredForLb / 100.0; // The EDS response contains one drop category. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerHundredForLb}}, - FractionalPercent::HUNDRED), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerHundredForLb}}; + args.drop_denominator = FractionalPercent::HUNDRED; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -1326,12 +1336,12 @@ TEST_F(SingleBalancerTest, DropPerTenThousand) { const uint32_t kDropPerTenThousandForLb = 1000; const double kDropRateForLb = kDropPerTenThousandForLb / 10000.0; // The EDS response contains one drop category. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerTenThousandForLb}}, - FractionalPercent::TEN_THOUSAND), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerTenThousandForLb}}; + args.drop_denominator = FractionalPercent::TEN_THOUSAND; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -1370,22 +1380,18 @@ TEST_F(SingleBalancerTest, DropUpdate) { const double KDropRateForLbAndThrottle = kDropRateForLb + (1 - kDropRateForLb) * kDropRateForThrottle; // The first EDS response contains one drop category. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerMillionForLb}}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerMillionForLb}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // The second EDS response contains two drop categories. // TODO(juanlishen): Change the EDS response sending to deterministic style // (e.g., by using condition variable) so that we can shorten the test // duration. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerMillionForLb}, - {kThrottleDropType, kDropPerMillionForThrottle}}), - 10000); + args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, + {kThrottleDropType, kDropPerMillionForThrottle}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 10000); WaitForAllBackends(); // Send kNumRpcs RPCs and count the drops. size_t num_drops = 0; @@ -1465,13 +1471,12 @@ TEST_F(SingleBalancerTest, DropAll) { const uint32_t kDropPerMillionForLb = 100000; const uint32_t kDropPerMillionForThrottle = 1000000; // The EDS response contains two drop categories. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerMillionForLb}, - {kThrottleDropType, kDropPerMillionForThrottle}}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, + {kThrottleDropType, kDropPerMillionForThrottle}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Send kNumRpcs RPCs and all of them are dropped. for (size_t i = 0; i < kNumRpcs; ++i) { EchoResponse response; @@ -1493,11 +1498,11 @@ TEST_F(SingleBalancerTest, Fallback) { kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); // Send non-empty serverlist only after kServerlistDelayMs. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(kNumBackendsInResolution /* start_index */)), - kServerlistDelayMs); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts(kNumBackendsInResolution)}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), + kServerlistDelayMs); // Wait until all the fallback backends are reachable. WaitForAllBackends(1 /* num_requests_multiple_of */, 0 /* start_index */, kNumBackendsInResolution /* stop_index */); @@ -1542,12 +1547,12 @@ TEST_F(SingleBalancerTest, FallbackUpdate) { kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); // Send non-empty serverlist only after kServerlistDelayMs. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups( - kNumBackendsInResolution + - kNumBackendsInResolutionUpdate /* start_index */)), - kServerlistDelayMs); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts(kNumBackendsInResolution + + kNumBackendsInResolutionUpdate)}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), + kServerlistDelayMs); // Wait until all the fallback backends are reachable. WaitForAllBackends(1 /* num_requests_multiple_of */, 0 /* start_index */, kNumBackendsInResolution /* stop_index */); @@ -1645,8 +1650,10 @@ TEST_F(SingleBalancerTest, FallbackIfResponseReceivedButChildNotReady) { SetNextResolutionForLbChannelAllBalancers(); // Send a serverlist that only contains an unreachable backend before fallback // timeout. - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse({{grpc_pick_unused_port_or_die()}}), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {grpc_pick_unused_port_or_die()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Because no child policy is ready before fallback timeout, we enter fallback // mode. WaitForBackend(0); @@ -1659,11 +1666,11 @@ TEST_F(SingleBalancerTest, FallbackModeIsExitedWhenBalancerSaysToDropAllCalls) { // Enter fallback mode because the LB channel fails to connect. WaitForBackend(0); // Return a new balancer that sends a response to drop all calls. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse(GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, 1000000}}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, 1000000}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); SetNextResolutionForLbChannelAllBalancers(); // Send RPCs until failure. gpr_timespec deadline = gpr_time_add( @@ -1683,8 +1690,10 @@ TEST_F(SingleBalancerTest, FallbackModeIsExitedAfterChildRready) { WaitForBackend(0); // Return a new balancer that sends a dead backend. ShutdownBackend(1); - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse({{backends_[1]->port()}}), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {backends_[1]->port()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); SetNextResolutionForLbChannelAllBalancers(); // The state (TRANSIENT_FAILURE) update from the child policy will be ignored // because we are still in fallback mode. @@ -1708,8 +1717,10 @@ TEST_F(SingleBalancerTest, FallbackModeIsExitedAfterChildRready) { TEST_F(SingleBalancerTest, BackendsRestart) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); - ScheduleResponseForBalancer( - 0, EdsServiceImpl::BuildResponse(GetBackendPortsInGroups()), 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); WaitForAllBackends(); // Stop backends. RPCs should fail. ShutdownAllBackends(); @@ -1728,12 +1739,14 @@ class UpdatesTest : public XdsEnd2endTest { TEST_F(UpdatesTest, UpdateBalancersButKeepUsingOriginalBalancer) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); - auto first_backend = GetBackendPortsInGroups(0, 1); - auto second_backend = GetBackendPortsInGroups(1, 2); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(first_backend), - 0); - ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(second_backend), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {backends_[0]->port()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality0", {backends_[1]->port()}}, + }); + ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(args), 0); // Wait until the first backend is ready. WaitForBackend(0); @@ -1781,12 +1794,14 @@ TEST_F(UpdatesTest, UpdateBalancersButKeepUsingOriginalBalancer) { TEST_F(UpdatesTest, UpdateBalancerName) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); - auto first_backend = GetBackendPortsInGroups(0, 1); - auto second_backend = GetBackendPortsInGroups(1, 2); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(first_backend), - 0); - ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(second_backend), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {backends_[0]->port()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality0", {backends_[1]->port()}}, + }); + ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(args), 0); // Wait until the first backend is ready. WaitForBackend(0); @@ -1852,12 +1867,14 @@ TEST_F(UpdatesTest, UpdateBalancerName) { TEST_F(UpdatesTest, UpdateBalancersRepeated) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannelAllBalancers(); - auto first_backend = GetBackendPortsInGroups(0, 1); - auto second_backend = GetBackendPortsInGroups(1, 2); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(first_backend), - 0); - ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(second_backend), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {backends_[0]->port()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality0", {backends_[1]->port()}}, + }); + ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(args), 0); // Wait until the first backend is ready. WaitForBackend(0); @@ -1920,12 +1937,14 @@ TEST_F(UpdatesTest, UpdateBalancersRepeated) { TEST_F(UpdatesTest, UpdateBalancersDeadUpdate) { SetNextResolution({}, kDefaultServiceConfig_.c_str()); SetNextResolutionForLbChannel({balancers_[0]->port()}); - auto first_backend = GetBackendPortsInGroups(0, 1); - auto second_backend = GetBackendPortsInGroups(1, 2); - ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(first_backend), - 0); - ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(second_backend), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", {backends_[0]->port()}}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality0", {backends_[1]->port()}}, + }); + ScheduleResponseForBalancer(1, EdsServiceImpl::BuildResponse(args), 0); // Start servers and send 10 RPCs per server. gpr_log(GPR_INFO, "========= BEFORE FIRST BATCH =========="); @@ -2007,10 +2026,10 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, Vanilla) { const size_t kNumRpcsPerAddress = 100; // TODO(juanlishen): Partition the backends after multiple localities is // tested. - ScheduleResponseForBalancer(0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(0, backends_.size())), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Wait until all backends are ready. int num_ok = 0; int num_failure = 0; @@ -2046,11 +2065,10 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, BalancerRestart) { const size_t kNumBackendsFirstPass = backends_.size() / 2; const size_t kNumBackendsSecondPass = backends_.size() - kNumBackendsFirstPass; - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(0, kNumBackendsFirstPass)), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts(0, kNumBackendsFirstPass)}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Wait until all backends returned by the balancer are ready. int num_ok = 0; int num_failure = 0; @@ -2077,11 +2095,10 @@ TEST_F(SingleBalancerWithClientLoadReportingTest, BalancerRestart) { } // Now restart the balancer, this time pointing to the new backends. balancers_[0]->Start(server_host_); - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(kNumBackendsFirstPass)), - 0); + args = EdsServiceImpl::ResponseArgs({ + {"locality0", GetBackendPorts(kNumBackendsFirstPass)}, + }); + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); // Wait for queries to start going to one of the new backends. // This tells us that we're now using the new serverlist. std::tie(num_ok, num_failure, num_drops) = @@ -2116,13 +2133,12 @@ TEST_F(SingleBalancerWithClientLoadReportingAndDropTest, Vanilla) { const double KDropRateForLbAndThrottle = kDropRateForLb + (1 - kDropRateForLb) * kDropRateForThrottle; // The EDS response contains two drop categories. - ScheduleResponseForBalancer( - 0, - EdsServiceImpl::BuildResponse( - GetBackendPortsInGroups(), {}, 0, - {{kLbDropType, kDropPerMillionForLb}, - {kThrottleDropType, kDropPerMillionForThrottle}}), - 0); + EdsServiceImpl::ResponseArgs args({ + {"locality0", GetBackendPorts()}, + }); + args.drop_categories = {{kLbDropType, kDropPerMillionForLb}, + {kThrottleDropType, kDropPerMillionForThrottle}}; + ScheduleResponseForBalancer(0, EdsServiceImpl::BuildResponse(args), 0); int num_ok = 0; int num_failure = 0; int num_drops = 0; From e70788364bf38947e9d3afb820800b14e44829b9 Mon Sep 17 00:00:00 2001 From: Richard Belleville Date: Wed, 28 Aug 2019 13:50:37 -0700 Subject: [PATCH 56/57] Make dependency on template files explicit --- third_party/py/python_configure.bzl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl index 70380e9dde9..6f9a178a057 100644 --- a/third_party/py/python_configure.bzl +++ b/third_party/py/python_configure.bzl @@ -292,14 +292,24 @@ def _python_autoconf_impl(repository_ctx): python_configure = repository_rule( - implementation=_python_autoconf_impl, - environ=[ + implementation = _python_autoconf_impl, + environ = [ _BAZEL_SH, _PYTHON2_BIN_PATH, _PYTHON2_LIB_PATH, _PYTHON3_BIN_PATH, _PYTHON3_LIB_PATH, ], + attrs={ + "_build_tpl": attr.label( + default = Label("//third_party/py:BUILD.tpl"), + allow_single_file = True, + ), + "_variety_tpl": attr.label( + default = Label("//third_party/py:variety.tpl"), + allow_single_file = True, + ), + }, ) """Detects and configures the local Python. From 4dfa808e75fbf0fd94a9787c596bedaabb684215 Mon Sep 17 00:00:00 2001 From: Prashant Jaikumar Date: Fri, 23 Aug 2019 17:12:41 -0700 Subject: [PATCH 57/57] Add test for timer expiry racing with cancelation --- test/cpp/common/timer_test.cc | 71 +++++++++++++++++++++++++++++------ 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/test/cpp/common/timer_test.cc b/test/cpp/common/timer_test.cc index 9b23be2885a..1abed1660e8 100644 --- a/test/cpp/common/timer_test.cc +++ b/test/cpp/common/timer_test.cc @@ -77,7 +77,7 @@ TEST_F(TimerTest, OneTimerExpires) { grpc_core::ExecCtx exec_ctx; grpc_timer timer; int timer_fired = 0; - grpc_timer_init(&timer, 500, + grpc_timer_init(&timer, grpc_core::ExecCtx::Get()->Now() + 500, GRPC_CLOSURE_CREATE( [](void* arg, grpc_error*) { int* timer_fired = static_cast(arg); @@ -102,7 +102,7 @@ TEST_F(TimerTest, MultipleTimersExpire) { grpc_timer timers[kNumTimers]; int timer_fired = 0; for (int i = 0; i < kNumTimers; ++i) { - grpc_timer_init(&timers[i], 500 + i, + grpc_timer_init(&timers[i], grpc_core::ExecCtx::Get()->Now() + 500 + i, GRPC_CLOSURE_CREATE( [](void* arg, grpc_error*) { int* timer_fired = static_cast(arg); @@ -129,7 +129,7 @@ TEST_F(TimerTest, CancelSomeTimers) { grpc_timer timers[kNumTimers]; int timer_fired = 0; for (int i = 0; i < kNumTimers; ++i) { - grpc_timer_init(&timers[i], 500 + i, + grpc_timer_init(&timers[i], grpc_core::ExecCtx::Get()->Now() + 500 + i, GRPC_CLOSURE_CREATE( [](void* arg, grpc_error* error) { if (error == GRPC_ERROR_CANCELLED) { @@ -157,17 +157,66 @@ TEST_F(TimerTest, CancelSomeTimers) { // Enable the following test after // https://github.com/grpc/grpc/issues/20049 has been fixed. -#if 0 -TEST_F(TimerTest, TimerNotCanceled) { +TEST_F(TimerTest, DISABLED_TimerNotCanceled) { grpc_core::ExecCtx exec_ctx; grpc_timer timer; - grpc_timer_init(&timer, 10000, - GRPC_CLOSURE_CREATE( - [](void*, grpc_error*) { - }, - nullptr, grpc_schedule_on_exec_ctx)); + grpc_timer_init(&timer, grpc_core::ExecCtx::Get()->Now() + 10000, + GRPC_CLOSURE_CREATE([](void*, grpc_error*) {}, nullptr, + grpc_schedule_on_exec_ctx)); +} + +// Enable the following test after +// https://github.com/grpc/grpc/issues/20064 has been fixed. +TEST_F(TimerTest, DISABLED_CancelRace) { + MAYBE_SKIP_TEST; + grpc_core::ExecCtx exec_ctx; + const int kNumTimers = 10; + grpc_timer timers[kNumTimers]; + for (int i = 0; i < kNumTimers; ++i) { + grpc_timer* arg = (i != 0) ? &timers[i - 1] : nullptr; + grpc_timer_init(&timers[i], grpc_core::ExecCtx::Get()->Now() + 100, + GRPC_CLOSURE_CREATE( + [](void* arg, grpc_error* error) { + grpc_timer* timer = static_cast(arg); + if (timer) { + grpc_timer_cancel(timer); + } + }, + arg, grpc_schedule_on_exec_ctx)); + } + gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); +} + +// Enable the following test after +// https://github.com/grpc/grpc/issues/20066 has been fixed. +TEST_F(TimerTest, DISABLED_CancelNextTimer) { + MAYBE_SKIP_TEST; + grpc_core::ExecCtx exec_ctx; + const int kNumTimers = 10; + grpc_timer timers[kNumTimers]; + + for (int i = 0; i < kNumTimers; ++i) { + grpc_timer_init_unset(&timers[i]); + } + + for (int i = 0; i < kNumTimers; ++i) { + grpc_timer* arg = nullptr; + if (i < kNumTimers - 1) { + arg = &timers[i + 1]; + } + grpc_timer_init(&timers[i], grpc_core::ExecCtx::Get()->Now() + 100, + GRPC_CLOSURE_CREATE( + [](void* arg, grpc_error* error) { + grpc_timer* timer = static_cast(arg); + if (timer) { + grpc_timer_cancel(timer); + } + }, + arg, grpc_schedule_on_exec_ctx)); + } + grpc_timer_cancel(&timers[0]); + gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(100)); } -#endif int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv);