From 594e1f6a64a24f0f700819b6cde4cdde19c645b0 Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Sat, 25 Apr 2020 16:41:32 -1000 Subject: [PATCH 01/45] py_proto_library uses workspace and pkg paths All python imports currently are added to the runfiles under __main__ which is only the default when no workspace name is provided. This change supports both empty workspace names, and specified workspace names. This also supports python libs not anchored at root --- bazel/python_rules.bzl | 4 +- bazel/test/python_test_repo/BUILD | 2 + bazel/test/python_test_repo/WORKSPACE | 3 + .../namespaced/upper/example/BUILD | 149 ++++++++++++++++++ .../upper/example/import_no_strip_test.py | 21 +++ .../upper/example/import_strip_test.py | 21 +++ .../upper/example/namespace_test.py | 17 ++ .../upper/example/namespaced_dependency.proto | 27 ++++ .../upper/example/namespaced_example.proto | 38 +++++ .../upper/example/no_import_no_strip_test.py | 21 +++ .../upper/example/no_import_strip_test.py | 21 +++ 11 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/BUILD create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/namespaced_dependency.proto create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/namespaced_example.proto create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py create mode 100644 bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index 39fee5d4d34..b19819286e4 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -53,7 +53,7 @@ def _generate_py_impl(context): imports = [] if out_dir.import_path: - imports.append("__main__/%s" % out_dir.import_path) + imports.append("%s/%s/%s" % (context.workspace_name, context.label.package, out_dir.import_path)) return [ DefaultInfo(files = depset(direct = out_files)), @@ -166,6 +166,8 @@ def _generate_pb2_grpc_src_impl(context): imports = [] if out_dir.import_path: + #TODO: I believe this can be deleted, the rule requires a py_proto_library, and that rule will + # properly update imports. imports.append("__main__/%s" % out_dir.import_path) return [ diff --git a/bazel/test/python_test_repo/BUILD b/bazel/test/python_test_repo/BUILD index fb23cf3370f..e7d359c63d1 100644 --- a/bazel/test/python_test_repo/BUILD +++ b/bazel/test/python_test_repo/BUILD @@ -69,6 +69,8 @@ py2and3_test( # Test compatibility of py_proto_library and py_grpc_library rules with # proto_library targets as deps when the latter use import_prefix and/or # strip_import_prefix arguments +# +# See namespaced/upper/example for more encompassing tests. proto_library( name = "helloworld_moved_proto", srcs = ["helloworld.proto"], diff --git a/bazel/test/python_test_repo/WORKSPACE b/bazel/test/python_test_repo/WORKSPACE index 94e5c684f3e..a10b8f96768 100644 --- a/bazel/test/python_test_repo/WORKSPACE +++ b/bazel/test/python_test_repo/WORKSPACE @@ -3,6 +3,9 @@ local_repository( path = "../../..", ) +# Ensure rules don't rely on __main__ naming convention. +workspace(name = "python_test_repo") + load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") grpc_deps() diff --git a/bazel/test/python_test_repo/namespaced/upper/example/BUILD b/bazel/test/python_test_repo/namespaced/upper/example/BUILD new file mode 100644 index 00000000000..9265b94d49b --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/BUILD @@ -0,0 +1,149 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load( + "@com_github_grpc_grpc//bazel:python_rules.bzl", + "py2and3_test", + "py_grpc_library", + "py_proto_library", +) + +_IMPORT_PREFIX = "foo/bar" + +_STRIP_PREFIX = "/%s" % package_name() + +proto_library( + name = "import_no_strip_proto", + srcs = ["namespaced_example.proto"], + import_prefix = _IMPORT_PREFIX, + strip_import_prefix = None, +) + +proto_library( + name = "import_strip_proto", + srcs = ["namespaced_example.proto"], + import_prefix = _IMPORT_PREFIX, + strip_import_prefix = _STRIP_PREFIX, +) + +proto_library( + name = "no_import_no_strip_proto", + srcs = ["namespaced_example.proto"], + import_prefix = None, + strip_import_prefix = None, +) + +proto_library( + name = "no_import_strip_proto", + srcs = ["namespaced_example.proto"], + import_prefix = None, + strip_import_prefix = _STRIP_PREFIX, +) + +py_proto_library( + name = "import_no_strip_py_pb2", + deps = ["import_no_strip_proto"], +) + +py_grpc_library( + name = "import_no_strip_py_pb2_grpc", + srcs = ["import_no_strip_proto"], + deps = ["import_no_strip_py_pb2"], +) + +py_proto_library( + name = "import_strip_py_pb2", + deps = ["import_strip_proto"], +) + +py_grpc_library( + name = "import_strip_py_pb2_grpc", + srcs = ["import_strip_proto"], + deps = ["import_strip_py_pb2"], +) + +py_proto_library( + name = "no_import_no_strip_py_pb2", + deps = ["no_import_no_strip_proto"], +) + +py_grpc_library( + name = "no_import_no_strip_py_pb2_grpc", + srcs = ["no_import_no_strip_proto"], + deps = ["no_import_no_strip_py_pb2"], +) + +py_proto_library( + name = "no_import_strip_py_pb2", + deps = ["no_import_strip_proto"], +) + +py_grpc_library( + name = "no_import_strip_py_pb2_grpc", + srcs = ["no_import_strip_proto"], + deps = ["no_import_strip_py_pb2"], +) + +################# +# Namespace Tests +################# + +# Most examples with protos have all proto packages rooted at the workspace root. i.e. google/api has +# a directory structure: +# - WORKSPACE +# - /google +# - /api +# - files.proto +# +# But if you can't anchor the protos at the root, you have to use strip and import prefixes. This results +# in the following directory layout for python, which needs to properly be added to the imports. +# +# No Import or Strip (Can't compile if there are any proto dependencies) +# bazel-out/darwin-fastbuild/bin/namespaced/upper/example/namespaced_example_pb2.py +# +# No import Prefix (Can't compile if there are any proto dependencies) +# bazel-out/darwin-fastbuild/bin/namespaced/upper/example/_virtual_imports/namespaced_example_proto/namespaced_example_pb2.py +# +# No strip prefix (Can't compile if there are any proto dependencies) +# bazel-out/darwin-fastbuild/bin/namespaced/upper/example/_virtual_imports/namespaced_example_proto/upper/example/namespaced/upper/example/namespaced_example_pb2.py +# +# Both Import and Strip +# bazel-out/darwin-fastbuild/bin/namespaced/upper/example/_virtual_imports/namespaced_example_proto/upper/example/namespaced_example_pb2.py + +py2and3_test( + "import_no_strip_test", + srcs = ["import_no_strip_test.py"], + main = "import_no_strip_test.py", + deps = [ + ":import_no_strip_py_pb2", + ":import_no_strip_py_pb2_grpc", + ], +) + +py2and3_test( + "import_strip_test", + srcs = ["import_strip_test.py"], + main = "import_strip_test.py", + deps = [ + ":import_strip_py_pb2", + ":import_strip_py_pb2_grpc", + ], +) + +py2and3_test( + "no_import_no_strip_test", + srcs = ["no_import_no_strip_test.py"], + main = "no_import_no_strip_test.py", + deps = [ + ":no_import_no_strip_py_pb2", + ":no_import_no_strip_py_pb2_grpc", + ], +) + +py2and3_test( + "no_import_strip_test", + srcs = ["no_import_strip_test.py"], + main = "no_import_strip_test.py", + deps = [ + ":no_import_strip_py_pb2", + ":no_import_strip_py_pb2_grpc", + ], +) diff --git a/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py new file mode 100644 index 00000000000..f22090f5533 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py @@ -0,0 +1,21 @@ +import logging +import unittest + + +class ImportTest(unittest.TestCase): + def test_import(self): + from foo.bar.namespaced.upper.example.namespaced_example_pb2 import NamespacedExample + namespaced_example = NamespacedExample() + namespaced_example.value = "hello" + # Dummy assert, important part is namespaced example was imported. + self.assertEqual(namespaced_example.value, "hello") + + def test_grpc(self): + from foo.bar.namespaced.upper.example.namespaced_example_pb2_grpc import NamespacedServiceStub + # No error from import + self.assertEqual(1, 1) + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() diff --git a/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py new file mode 100644 index 00000000000..0c5ae8b5c11 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py @@ -0,0 +1,21 @@ +import logging +import unittest + + +class ImportTest(unittest.TestCase): + def test_import(self): + from foo.bar.namespaced_example_pb2 import NamespacedExample + namespaced_example = NamespacedExample() + namespaced_example.value = "hello" + # Dummy assert, important part is namespaced example was imported. + self.assertEqual(namespaced_example.value, "hello") + + def test_grpc(self): + from foo.bar.namespaced_example_pb2_grpc import NamespacedServiceStub + # No error from import + self.assertEqual(1, 1) + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() diff --git a/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py b/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py new file mode 100644 index 00000000000..daed0d82258 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py @@ -0,0 +1,17 @@ +import logging +import unittest + +import NamespacedExample + + +class ImportTest(unittest.TestCase): + def test_import(self): + namespaced_example = NamespacedExample() + namespaced_example.value = "hello" + # Dummy assert, important part is namespaced example was imported. + self.assertEqual(namespaced_example.value, "hello") + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() diff --git a/bazel/test/python_test_repo/namespaced/upper/example/namespaced_dependency.proto b/bazel/test/python_test_repo/namespaced/upper/example/namespaced_dependency.proto new file mode 100644 index 00000000000..5820e1c5563 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/namespaced_dependency.proto @@ -0,0 +1,27 @@ +// Copyright 2020 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. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.namespaced"; +option java_outer_classname = "NamespacedDependencyProtos"; +option objc_class_prefix = "NEP"; + +package upper.example; + + +message NamespacedDependency { + int32 value = 1; +} diff --git a/bazel/test/python_test_repo/namespaced/upper/example/namespaced_example.proto b/bazel/test/python_test_repo/namespaced/upper/example/namespaced_example.proto new file mode 100644 index 00000000000..85061aae5ce --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/namespaced_example.proto @@ -0,0 +1,38 @@ +// Copyright 2020 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. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.examples.namespaced"; +option java_outer_classname = "NamespacedExampleProtos"; +option objc_class_prefix = "NEP"; + +package upper.example; + +// TODO: dependencies are still broken +// Need to do something like this: https://packaging.python.org/guides/packaging-namespace-packages/ +// import "upper/example/namespaced_dependency.proto"; + +message NamespacedExample { + string value = 1; + + // TODO: dependencies are still broken + // NamespacedDependency dependency = 2; +} + +service NamespacedService { + rpc SayHello (NamespacedExample) returns (NamespacedExample) {} +} + diff --git a/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py new file mode 100644 index 00000000000..1c3d0acd888 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py @@ -0,0 +1,21 @@ +import logging +import unittest + + +class ImportTest(unittest.TestCase): + def test_import(self): + from namespaced.upper.example.namespaced_example_pb2 import NamespacedExample + namespaced_example = NamespacedExample() + namespaced_example.value = "hello" + # Dummy assert, important part is namespaced example was imported. + self.assertEqual(namespaced_example.value, "hello") + + def test_grpc(self): + from namespaced.upper.example.namespaced_example_pb2_grpc import NamespacedServiceStub + # No error from import + self.assertEqual(1, 1) + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() diff --git a/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py new file mode 100644 index 00000000000..74638afb374 --- /dev/null +++ b/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py @@ -0,0 +1,21 @@ +import logging +import unittest + + +class ImportTest(unittest.TestCase): + def test_import(self): + from namespaced_example_pb2 import NamespacedExample + namespaced_example = NamespacedExample() + namespaced_example.value = "hello" + # Dummy assert, important part is namespaced example was imported. + self.assertEqual(namespaced_example.value, "hello") + + def test_grpc(self): + from namespaced_example_pb2_grpc import NamespacedServiceStub + # No error from import + self.assertEqual(1, 1) + + +if __name__ == '__main__': + logging.basicConfig() + unittest.main() From 67f3ebd90ef190fd78a8e357d5a40b5ab926e2ba Mon Sep 17 00:00:00 2001 From: Matt Wilson Date: Wed, 29 Apr 2020 11:12:47 -1000 Subject: [PATCH 02/45] PR Feedback. --- bazel/python_rules.bzl | 9 ++------- .../namespaced/upper/example/namespace_test.py | 17 ----------------- 2 files changed, 2 insertions(+), 24 deletions(-) delete mode 100644 bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py diff --git a/bazel/python_rules.bzl b/bazel/python_rules.bzl index b19819286e4..8418c291c6a 100644 --- a/bazel/python_rules.bzl +++ b/bazel/python_rules.bzl @@ -164,17 +164,12 @@ def _generate_pb2_grpc_src_impl(context): mnemonic = "ProtocInvocation", ) - imports = [] - if out_dir.import_path: - #TODO: I believe this can be deleted, the rule requires a py_proto_library, and that rule will - # properly update imports. - imports.append("__main__/%s" % out_dir.import_path) - return [ DefaultInfo(files = depset(direct = out_files)), PyInfo( transitive_sources = depset(), - imports = depset(direct = imports), + # Imports are already configured by the generated py impl + imports = depset(), ), ] diff --git a/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py b/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py deleted file mode 100644 index daed0d82258..00000000000 --- a/bazel/test/python_test_repo/namespaced/upper/example/namespace_test.py +++ /dev/null @@ -1,17 +0,0 @@ -import logging -import unittest - -import NamespacedExample - - -class ImportTest(unittest.TestCase): - def test_import(self): - namespaced_example = NamespacedExample() - namespaced_example.value = "hello" - # Dummy assert, important part is namespaced example was imported. - self.assertEqual(namespaced_example.value, "hello") - - -if __name__ == '__main__': - logging.basicConfig() - unittest.main() From 7f2eaaabac3e4e5007314c73b4ad11418e64c138 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Wed, 24 Jun 2020 17:34:06 -0700 Subject: [PATCH 03/45] Move create_channel and credentials from ::grpc_impl to ::grpc Reverts: https://github.com/grpc/grpc/pull/18374 and https://github.com/grpc/grpc/pull/18444 Credentials and create_channel are very closely intertwined, so it is easier to migrate them together. --- BUILD | 2 - BUILD.gn | 2 - CMakeLists.txt | 2 - Makefile | 2 - build_autogenerated.yaml | 4 - gRPC-C++.podspec | 1 - include/grpcpp/create_channel.h | 59 ++- include/grpcpp/create_channel_impl.h | 78 ---- .../grpcpp/impl/codegen/client_context_impl.h | 8 +- include/grpcpp/security/credentials.h | 388 ++++++++++++++---- include/grpcpp/security/credentials_impl.h | 358 ---------------- include/grpcpp/security/server_credentials.h | 12 +- .../grpcpp/security/server_credentials_impl.h | 2 +- .../grpcpp/security/tls_credentials_options.h | 4 +- .../grpcpp/support/channel_arguments_impl.h | 4 +- src/cpp/client/client_context.cc | 2 +- src/cpp/client/create_channel.cc | 10 +- src/cpp/client/credentials_cc.cc | 4 +- src/cpp/client/cronet_credentials.cc | 5 +- src/cpp/client/insecure_credentials.cc | 4 +- src/cpp/client/secure_credentials.cc | 5 +- src/cpp/client/secure_credentials.h | 8 +- src/cpp/common/tls_credentials_options.cc | 4 +- .../common/tls_credentials_options_util.cc | 4 +- src/cpp/common/tls_credentials_options_util.h | 4 +- src/cpp/server/secure_server_credentials.cc | 2 +- tools/doxygen/Doxyfile.c++ | 2 - tools/doxygen/Doxyfile.c++.internal | 2 - 28 files changed, 379 insertions(+), 603 deletions(-) delete mode 100644 include/grpcpp/create_channel_impl.h delete mode 100644 include/grpcpp/security/credentials_impl.h diff --git a/BUILD b/BUILD index 0d616078bd2..c57e36c912b 100644 --- a/BUILD +++ b/BUILD @@ -225,7 +225,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", - "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/create_channel_posix_impl.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", @@ -254,7 +253,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/auth_metadata_processor_impl.h", "include/grpcpp/security/credentials.h", - "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/BUILD.gn b/BUILD.gn index cb133df9924..941fef1c8ff 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1225,7 +1225,6 @@ config("grpc_config") { "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", - "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/create_channel_posix_impl.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", @@ -1312,7 +1311,6 @@ config("grpc_config") { "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/auth_metadata_processor_impl.h", "include/grpcpp/security/credentials.h", - "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f19de24db9..f7943e5e4c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2875,7 +2875,6 @@ foreach(_hdr include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/auth_metadata_processor_impl.h include/grpcpp/security/credentials.h - include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h @@ -3568,7 +3567,6 @@ foreach(_hdr include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/auth_metadata_processor_impl.h include/grpcpp/security/credentials.h - include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h diff --git a/Makefile b/Makefile index cf294e9b9ba..4c69d6f5108 100644 --- a/Makefile +++ b/Makefile @@ -5072,7 +5072,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/credentials.h \ - include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ @@ -5770,7 +5769,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/credentials.h \ - include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 8f6fc380b4e..90cb9b37f7d 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2329,7 +2329,6 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h - - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/create_channel_posix_impl.h - include/grpcpp/ext/health_check_service_server_builder_option.h @@ -2416,7 +2415,6 @@ libs: - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/auth_metadata_processor_impl.h - include/grpcpp/security/credentials.h - - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h @@ -2721,7 +2719,6 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h - - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/create_channel_posix_impl.h - include/grpcpp/ext/health_check_service_server_builder_option.h @@ -2808,7 +2805,6 @@ libs: - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/auth_metadata_processor_impl.h - include/grpcpp/security/credentials.h - - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index f7316b70fcf..de37ca66dd1 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -167,7 +167,6 @@ Pod::Spec.new do |s| 'include/grpcpp/security/auth_metadata_processor.h', 'include/grpcpp/security/auth_metadata_processor_impl.h', 'include/grpcpp/security/credentials.h', - 'include/grpcpp/security/credentials_impl.h', 'include/grpcpp/security/server_credentials.h', 'include/grpcpp/security/server_credentials_impl.h', 'include/grpcpp/security/tls_credentials_options.h', diff --git a/include/grpcpp/create_channel.h b/include/grpcpp/create_channel.h index 9b257ace945..4b94a08e45e 100644 --- a/include/grpcpp/create_channel.h +++ b/include/grpcpp/create_channel.h @@ -1,6 +1,6 @@ /* * - * Copyright 2019 gRPC authors. + * Copyright 2015 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,38 +19,59 @@ #ifndef GRPCPP_CREATE_CHANNEL_H #define GRPCPP_CREATE_CHANNEL_H -#include +#include + +#include +#include +#include #include +#include namespace grpc { - -static inline std::shared_ptr<::grpc::Channel> CreateChannel( +/// Create a new \a Channel pointing to \a target. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +std::shared_ptr CreateChannel( const grpc::string& target, - const std::shared_ptr& creds) { - return ::grpc_impl::CreateChannelImpl(target, creds); -} + const std::shared_ptr& creds); -static inline std::shared_ptr<::grpc::Channel> CreateCustomChannel( +/// Create a new \em custom \a Channel pointing to \a target. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr CreateCustomChannel( const grpc::string& target, const std::shared_ptr& creds, - const ChannelArguments& args) { - return ::grpc_impl::CreateCustomChannelImpl(target, creds, args); -} + const ChannelArguments& args); namespace experimental { - -static inline std::shared_ptr<::grpc::Channel> -CreateCustomChannelWithInterceptors( +/// Create a new \em custom \a Channel pointing to \a target with \a +/// interceptors being invoked per call. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr CreateCustomChannelWithInterceptors( const grpc::string& target, const std::shared_ptr& creds, const ChannelArguments& args, std::vector< std::unique_ptr> - interceptor_creators) { - return ::grpc_impl::experimental::CreateCustomChannelWithInterceptors( - target, creds, args, std::move(interceptor_creators)); -} - + interceptor_creators); } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/create_channel_impl.h b/include/grpcpp/create_channel_impl.h deleted file mode 100644 index 02896e66444..00000000000 --- a/include/grpcpp/create_channel_impl.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Copyright 2015 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. - * - */ - -#ifndef GRPCPP_CREATE_CHANNEL_IMPL_H -#define GRPCPP_CREATE_CHANNEL_IMPL_H - -#include - -#include -#include -#include -#include -#include - -namespace grpc_impl { -/// Create a new \a Channel pointing to \a target. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -std::shared_ptr<::grpc::Channel> CreateChannelImpl( - const grpc::string& target, - const std::shared_ptr<::grpc::ChannelCredentials>& creds); - -/// Create a new \em custom \a Channel pointing to \a target. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr<::grpc::Channel> CreateCustomChannelImpl( - const grpc::string& target, - const std::shared_ptr<::grpc::ChannelCredentials>& creds, - const ::grpc::ChannelArguments& args); - -namespace experimental { -/// Create a new \em custom \a Channel pointing to \a target with \a -/// interceptors being invoked per call. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr<::grpc::Channel> CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, - const ::grpc::ChannelArguments& args, - std::vector< - std::unique_ptr> - interceptor_creators); -} // namespace experimental -} // namespace grpc_impl - -#endif // GRPCPP_CREATE_CHANNEL_IMPL_H diff --git a/include/grpcpp/impl/codegen/client_context_impl.h b/include/grpcpp/impl/codegen/client_context_impl.h index b8e90722b25..c1ab794bfed 100644 --- a/include/grpcpp/impl/codegen/client_context_impl.h +++ b/include/grpcpp/impl/codegen/client_context_impl.h @@ -58,6 +58,7 @@ struct grpc_call; namespace grpc { +class CallCredentials; class ChannelInterface; namespace internal { @@ -88,7 +89,6 @@ class ClientCallbackUnaryImpl; class ClientContextAccessor; } // namespace internal -class CallCredentials; class Channel; class CompletionQueue; class ServerContext; @@ -321,14 +321,14 @@ class ClientContext { /// /// \see https://grpc.io/docs/guides/auth.html void set_credentials( - const std::shared_ptr& creds); + const std::shared_ptr& creds); /// EXPERIMENTAL debugging API /// /// Returns the credentials for the client call. This should be used only in /// tests and for diagnostic purposes, and should not be used by application /// logic. - std::shared_ptr credentials() { return creds_; } + std::shared_ptr credentials() { return creds_; } /// Return the compression algorithm the client call will request be used. /// Note that the gRPC runtime may decide to ignore this request, for example, @@ -496,7 +496,7 @@ class ClientContext { bool call_canceled_; gpr_timespec deadline_; grpc::string authority_; - std::shared_ptr creds_; + std::shared_ptr creds_; mutable std::shared_ptr auth_context_; struct census_context* census_context_; std::multimap send_initial_metadata_; diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 0449017e77b..418c8ae069b 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -19,123 +19,337 @@ #ifndef GRPCPP_SECURITY_CREDENTIALS_H #define GRPCPP_SECURITY_CREDENTIALS_H -#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct grpc_call; namespace grpc { +class CallCredentials; +class SecureCallCredentials; +class SecureChannelCredentials; +class ChannelCredentials; -typedef ::grpc_impl::ChannelCredentials ChannelCredentials; -typedef ::grpc_impl::CallCredentials CallCredentials; -typedef ::grpc_impl::SslCredentialsOptions SslCredentialsOptions; -typedef ::grpc_impl::SecureCallCredentials SecureCallCredentials; -typedef ::grpc_impl::SecureChannelCredentials SecureChannelCredentials; -typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; +std::shared_ptr CreateCustomChannel( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args); -static inline std::shared_ptr -GoogleDefaultCredentials() { - return ::grpc_impl::GoogleDefaultCredentials(); +namespace experimental { +std::shared_ptr CreateCustomChannelWithInterceptors( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args, + std::vector< + std::unique_ptr> + interceptor_creators); } -static inline std::shared_ptr SslCredentials( - const SslCredentialsOptions& options) { - return ::grpc_impl::SslCredentials(options); -} +/// A channel credentials object encapsulates all the state needed by a client +/// to authenticate with a server for a given channel. +/// It can make various assertions, e.g., about the client’s identity, role +/// for all the calls on that channel. +/// +/// \see https://grpc.io/docs/guides/auth.html +class ChannelCredentials : private grpc::GrpcLibraryCodegen { + public: + ChannelCredentials(); + ~ChannelCredentials(); -static inline std::shared_ptr -GoogleComputeEngineCredentials() { - return ::grpc_impl::GoogleComputeEngineCredentials(); -} + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + + virtual SecureChannelCredentials* AsSecureCredentials() = 0; + + private: + friend std::shared_ptr CreateCustomChannel( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args); + + friend std::shared_ptr + grpc::experimental::CreateCustomChannelWithInterceptors( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args, + std::vector> + interceptor_creators); + + virtual std::shared_ptr CreateChannelImpl( + const grpc::string& target, const ChannelArguments& args) = 0; + + // This function should have been a pure virtual function, but it is + // implemented as a virtual function so that it does not break API. + virtual std::shared_ptr CreateChannelWithInterceptors( + const grpc::string& /*target*/, const ChannelArguments& /*args*/, + std::vector> + /*interceptor_creators*/) { + return nullptr; + } +}; + +/// A call credentials object encapsulates the state needed by a client to +/// authenticate with a server for a given call on a channel. +/// +/// \see https://grpc.io/docs/guides/auth.html +class CallCredentials : private grpc::GrpcLibraryCodegen { + public: + CallCredentials(); + ~CallCredentials(); + + /// Apply this instance's credentials to \a call. + virtual bool ApplyToCall(grpc_call* call) = 0; + virtual grpc::string DebugString() { + return "CallCredentials did not provide a debug string"; + } + + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + + friend std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); + + virtual SecureCallCredentials* AsSecureCredentials() = 0; +}; + +/// Options used to build SslCredentials. +struct SslCredentialsOptions { + /// The buffer containing the PEM encoding of the server root certificates. If + /// this parameter is empty, the default roots will be used. The default + /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH + /// environment variable pointing to a file on the file system containing the + /// roots. + grpc::string pem_root_certs; + + /// The buffer containing the PEM encoding of the client's private key. This + /// parameter can be empty if the client does not have a private key. + grpc::string pem_private_key; + + /// The buffer containing the PEM encoding of the client's certificate chain. + /// This parameter can be empty if the client does not have a certificate + /// chain. + grpc::string pem_cert_chain; +}; + +// Factories for building different types of Credentials The functions may +// return empty shared_ptr when credentials cannot be created. If a +// Credentials pointer is returned, it can still be invalid when used to create +// a channel. A lame channel will be created then and all rpcs will fail on it. + +/// Builds credentials with reasonable defaults. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleDefaultCredentials(); + +/// Builds SSL Credentials given SSL specific options +std::shared_ptr SslCredentials( + const SslCredentialsOptions& options); -/// Constant for maximum auth token lifetime. -constexpr long kMaxAuthTokenLifetimeSecs = - ::grpc_impl::kMaxAuthTokenLifetimeSecs; +/// Builds credentials for use when running in GCE +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleComputeEngineCredentials(); -static inline std::shared_ptr -ServiceAccountJWTAccessCredentials( +constexpr long kMaxAuthTokenLifetimeSecs = 3600; + +/// Builds Service Account JWT Access credentials. +/// json_key is the JSON key string containing the client's private key. +/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token +/// (JWT) created with this credentials. It should not exceed +/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. +std::shared_ptr ServiceAccountJWTAccessCredentials( const grpc::string& json_key, - long token_lifetime_seconds = grpc::kMaxAuthTokenLifetimeSecs) { - return ::grpc_impl::ServiceAccountJWTAccessCredentials( - json_key, token_lifetime_seconds); -} + long token_lifetime_seconds = kMaxAuthTokenLifetimeSecs); -static inline std::shared_ptr -GoogleRefreshTokenCredentials(const grpc::string& json_refresh_token) { - return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token); -} +/// Builds refresh token credentials. +/// json_refresh_token is the JSON string containing the refresh token along +/// with a client_id and client_secret. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleRefreshTokenCredentials( + const grpc::string& json_refresh_token); -static inline std::shared_ptr -AccessTokenCredentials(const grpc::string& access_token) { - return ::grpc_impl::AccessTokenCredentials(access_token); -} +/// Builds access token credentials. +/// access_token is an oauth2 access token that was fetched using an out of band +/// mechanism. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr AccessTokenCredentials( + const grpc::string& access_token); -static inline std::shared_ptr GoogleIAMCredentials( +/// Builds IAM credentials. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleIAMCredentials( const grpc::string& authorization_token, - const grpc::string& authority_selector) { - return ::grpc_impl::GoogleIAMCredentials(authorization_token, - authority_selector); -} + const grpc::string& authority_selector); -static inline std::shared_ptr CompositeChannelCredentials( +/// Combines a channel credentials and a call credentials into a composite +/// channel credentials. +std::shared_ptr CompositeChannelCredentials( const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds) { - return ::grpc_impl::CompositeChannelCredentials(channel_creds, call_creds); -} + const std::shared_ptr& call_creds); -static inline std::shared_ptr -CompositeCallCredentials(const std::shared_ptr& creds1, - const std::shared_ptr& creds2) { - return ::grpc_impl::CompositeCallCredentials(creds1, creds2); -} +/// Combines two call credentials objects into a composite call credentials. +std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); -static inline std::shared_ptr -InsecureChannelCredentials() { - return ::grpc_impl::InsecureChannelCredentials(); -} +/// Credentials for an unencrypted, unauthenticated channel +std::shared_ptr InsecureChannelCredentials(); -typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; +/// User defined metadata credentials. +class MetadataCredentialsPlugin { + public: + virtual ~MetadataCredentialsPlugin() {} -static inline std::shared_ptr -MetadataCredentialsFromPlugin( - std::unique_ptr plugin) { - return ::grpc_impl::MetadataCredentialsFromPlugin(std::move(plugin)); -} + /// If this method returns true, the Process function will be scheduled in + /// a different thread from the one processing the call. + virtual bool IsBlocking() const { return true; } + + /// Type of credentials this plugin is implementing. + virtual const char* GetType() const { return ""; } + + /// Gets the auth metatada produced by this plugin. + /// The fully qualified method name is: + /// service_url + "/" + method_name. + /// The channel_auth_context contains (among other things), the identity of + /// the server. + virtual grpc::Status GetMetadata( + grpc::string_ref service_url, grpc::string_ref method_name, + const grpc::AuthContext& channel_auth_context, + std::multimap* metadata) = 0; + + virtual grpc::string DebugString() { + return "MetadataCredentialsPlugin did not provide a debug string"; + } +}; + +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin); namespace experimental { -typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions; +/// Options for creating STS Oauth Token Exchange credentials following the IETF +/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. +/// Optional fields may be set to empty string. It is the responsibility of the +/// caller to ensure that the subject and actor tokens are refreshed on disk at +/// the specified paths. +struct StsCredentialsOptions { + grpc::string token_exchange_service_uri; // Required. + grpc::string resource; // Optional. + grpc::string audience; // Optional. + grpc::string scope; // Optional. + grpc::string requested_token_type; // Optional. + grpc::string subject_token_path; // Required. + grpc::string subject_token_type; // Required. + grpc::string actor_token_path; // Optional. + grpc::string actor_token_type; // Optional. +}; -static inline grpc::Status StsCredentialsOptionsFromJson( - const grpc::string& json_string, StsCredentialsOptions* options) { - return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string, - options); -} +/// Creates STS Options from a JSON string. The JSON schema is as follows: +/// { +/// "title": "STS Credentials Config", +/// "type": "object", +/// "required": ["token_exchange_service_uri", "subject_token_path", +/// "subject_token_type"], +/// "properties": { +/// "token_exchange_service_uri": { +/// "type": "string" +/// }, +/// "resource": { +/// "type": "string" +/// }, +/// "audience": { +/// "type": "string" +/// }, +/// "scope": { +/// "type": "string" +/// }, +/// "requested_token_type": { +/// "type": "string" +/// }, +/// "subject_token_path": { +/// "type": "string" +/// }, +/// "subject_token_type": { +/// "type": "string" +/// }, +/// "actor_token_path" : { +/// "type": "string" +/// }, +/// "actor_token_type": { +/// "type": "string" +/// } +/// } +/// } +grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, + StsCredentialsOptions* options); -static inline grpc::Status StsCredentialsOptionsFromEnv( - StsCredentialsOptions* options) { - return grpc_impl::experimental::StsCredentialsOptionsFromEnv(options); -} +/// Creates STS credentials options from the $STS_CREDENTIALS environment +/// variable. This environment variable points to the path of a JSON file +/// comforming to the schema described above. +grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); -static inline std::shared_ptr StsCredentials( - const StsCredentialsOptions& options) { - return grpc_impl::experimental::StsCredentials(options); -} +std::shared_ptr StsCredentials( + const StsCredentialsOptions& options); -typedef ::grpc_impl::experimental::AltsCredentialsOptions - AltsCredentialsOptions; +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin, + grpc_security_level min_security_level); -static inline std::shared_ptr AltsCredentials( - const AltsCredentialsOptions& options) { - return ::grpc_impl::experimental::AltsCredentials(options); -} +/// Options used to build AltsCredentials. +struct AltsCredentialsOptions { + /// service accounts of target endpoint that will be acceptable + /// by the client. If service accounts are provided and none of them matches + /// that of the server, authentication will fail. + std::vector target_service_accounts; +}; -static inline std::shared_ptr LocalCredentials( - grpc_local_connect_type type) { - return ::grpc_impl::experimental::LocalCredentials(type); -} +/// Builds ALTS Credentials given ALTS specific options +std::shared_ptr AltsCredentials( + const AltsCredentialsOptions& options); -static inline std::shared_ptr TlsCredentials( - const ::grpc_impl::experimental::TlsCredentialsOptions& options) { - return ::grpc_impl::experimental::TlsCredentials(options); -} +/// Builds Local Credentials. +std::shared_ptr LocalCredentials( + grpc_local_connect_type type); + +/// Builds TLS Credentials given TLS options. +std::shared_ptr TlsCredentials( + const TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/credentials_impl.h b/include/grpcpp/security/credentials_impl.h deleted file mode 100644 index aed58283722..00000000000 --- a/include/grpcpp/security/credentials_impl.h +++ /dev/null @@ -1,358 +0,0 @@ -/* - * - * Copyright 2015 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. - * - */ - -#ifndef GRPCPP_SECURITY_CREDENTIALS_IMPL_H -#define GRPCPP_SECURITY_CREDENTIALS_IMPL_H - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct grpc_call; - -namespace grpc_impl { - -class ChannelCredentials; -class CallCredentials; -class SecureCallCredentials; -class SecureChannelCredentials; - -std::shared_ptr CreateCustomChannelImpl( - const grpc::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args); - -namespace experimental { -std::shared_ptr CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args, - std::vector< - std::unique_ptr> - interceptor_creators); -} - -/// A channel credentials object encapsulates all the state needed by a client -/// to authenticate with a server for a given channel. -/// It can make various assertions, e.g., about the client’s identity, role -/// for all the calls on that channel. -/// -/// \see https://grpc.io/docs/guides/auth.html -class ChannelCredentials : private grpc::GrpcLibraryCodegen { - public: - ChannelCredentials(); - ~ChannelCredentials(); - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - virtual SecureChannelCredentials* AsSecureCredentials() = 0; - - private: - friend std::shared_ptr CreateCustomChannelImpl( - const grpc::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args); - - friend std::shared_ptr - grpc_impl::experimental::CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args, - std::vector> - interceptor_creators); - - virtual std::shared_ptr CreateChannelImpl( - const grpc::string& target, const ChannelArguments& args) = 0; - - // This function should have been a pure virtual function, but it is - // implemented as a virtual function so that it does not break API. - virtual std::shared_ptr CreateChannelWithInterceptors( - const grpc::string& /*target*/, const ChannelArguments& /*args*/, - std::vector> - /*interceptor_creators*/) { - return nullptr; - } -}; - -/// A call credentials object encapsulates the state needed by a client to -/// authenticate with a server for a given call on a channel. -/// -/// \see https://grpc.io/docs/guides/auth.html -class CallCredentials : private grpc::GrpcLibraryCodegen { - public: - CallCredentials(); - ~CallCredentials(); - - /// Apply this instance's credentials to \a call. - virtual bool ApplyToCall(grpc_call* call) = 0; - virtual grpc::string DebugString() { - return "CallCredentials did not provide a debug string"; - } - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - friend std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - - virtual SecureCallCredentials* AsSecureCredentials() = 0; -}; - -/// Options used to build SslCredentials. -struct SslCredentialsOptions { - /// The buffer containing the PEM encoding of the server root certificates. If - /// this parameter is empty, the default roots will be used. The default - /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH - /// environment variable pointing to a file on the file system containing the - /// roots. - grpc::string pem_root_certs; - - /// The buffer containing the PEM encoding of the client's private key. This - /// parameter can be empty if the client does not have a private key. - grpc::string pem_private_key; - - /// The buffer containing the PEM encoding of the client's certificate chain. - /// This parameter can be empty if the client does not have a certificate - /// chain. - grpc::string pem_cert_chain; -}; - -// Factories for building different types of Credentials The functions may -// return empty shared_ptr when credentials cannot be created. If a -// Credentials pointer is returned, it can still be invalid when used to create -// a channel. A lame channel will be created then and all rpcs will fail on it. - -/// Builds credentials with reasonable defaults. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleDefaultCredentials(); - -/// Builds SSL Credentials given SSL specific options -std::shared_ptr SslCredentials( - const SslCredentialsOptions& options); - -/// Builds credentials for use when running in GCE -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleComputeEngineCredentials(); - -constexpr long kMaxAuthTokenLifetimeSecs = 3600; - -/// Builds Service Account JWT Access credentials. -/// json_key is the JSON key string containing the client's private key. -/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token -/// (JWT) created with this credentials. It should not exceed -/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. -std::shared_ptr ServiceAccountJWTAccessCredentials( - const grpc::string& json_key, - long token_lifetime_seconds = grpc_impl::kMaxAuthTokenLifetimeSecs); - -/// Builds refresh token credentials. -/// json_refresh_token is the JSON string containing the refresh token along -/// with a client_id and client_secret. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleRefreshTokenCredentials( - const grpc::string& json_refresh_token); - -/// Builds access token credentials. -/// access_token is an oauth2 access token that was fetched using an out of band -/// mechanism. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr AccessTokenCredentials( - const grpc::string& access_token); - -/// Builds IAM credentials. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleIAMCredentials( - const grpc::string& authorization_token, - const grpc::string& authority_selector); - -/// Combines a channel credentials and a call credentials into a composite -/// channel credentials. -std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - -/// Combines two call credentials objects into a composite call credentials. -std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - -/// Credentials for an unencrypted, unauthenticated channel -std::shared_ptr InsecureChannelCredentials(); - -/// User defined metadata credentials. -class MetadataCredentialsPlugin { - public: - virtual ~MetadataCredentialsPlugin() {} - - /// If this method returns true, the Process function will be scheduled in - /// a different thread from the one processing the call. - virtual bool IsBlocking() const { return true; } - - /// Type of credentials this plugin is implementing. - virtual const char* GetType() const { return ""; } - - /// Gets the auth metatada produced by this plugin. - /// The fully qualified method name is: - /// service_url + "/" + method_name. - /// The channel_auth_context contains (among other things), the identity of - /// the server. - virtual grpc::Status GetMetadata( - grpc::string_ref service_url, grpc::string_ref method_name, - const grpc::AuthContext& channel_auth_context, - std::multimap* metadata) = 0; - - virtual grpc::string DebugString() { - return "MetadataCredentialsPlugin did not provide a debug string"; - } -}; - -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin); - -namespace experimental { - -/// Options for creating STS Oauth Token Exchange credentials following the IETF -/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. -/// Optional fields may be set to empty string. It is the responsibility of the -/// caller to ensure that the subject and actor tokens are refreshed on disk at -/// the specified paths. -struct StsCredentialsOptions { - grpc::string token_exchange_service_uri; // Required. - grpc::string resource; // Optional. - grpc::string audience; // Optional. - grpc::string scope; // Optional. - grpc::string requested_token_type; // Optional. - grpc::string subject_token_path; // Required. - grpc::string subject_token_type; // Required. - grpc::string actor_token_path; // Optional. - grpc::string actor_token_type; // Optional. -}; - -/// Creates STS Options from a JSON string. The JSON schema is as follows: -/// { -/// "title": "STS Credentials Config", -/// "type": "object", -/// "required": ["token_exchange_service_uri", "subject_token_path", -/// "subject_token_type"], -/// "properties": { -/// "token_exchange_service_uri": { -/// "type": "string" -/// }, -/// "resource": { -/// "type": "string" -/// }, -/// "audience": { -/// "type": "string" -/// }, -/// "scope": { -/// "type": "string" -/// }, -/// "requested_token_type": { -/// "type": "string" -/// }, -/// "subject_token_path": { -/// "type": "string" -/// }, -/// "subject_token_type": { -/// "type": "string" -/// }, -/// "actor_token_path" : { -/// "type": "string" -/// }, -/// "actor_token_type": { -/// "type": "string" -/// } -/// } -/// } -grpc::Status StsCredentialsOptionsFromJson(const grpc::string& json_string, - StsCredentialsOptions* options); - -/// Creates STS credentials options from the $STS_CREDENTIALS environment -/// variable. This environment variable points to the path of a JSON file -/// comforming to the schema described above. -grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); - -std::shared_ptr StsCredentials( - const StsCredentialsOptions& options); - -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin, - grpc_security_level min_security_level); - -/// Options used to build AltsCredentials. -struct AltsCredentialsOptions { - /// service accounts of target endpoint that will be acceptable - /// by the client. If service accounts are provided and none of them matches - /// that of the server, authentication will fail. - std::vector target_service_accounts; -}; - -/// Builds ALTS Credentials given ALTS specific options -std::shared_ptr AltsCredentials( - const AltsCredentialsOptions& options); - -/// Builds Local Credentials. -std::shared_ptr LocalCredentials( - grpc_local_connect_type type); - -/// Builds TLS Credentials given TLS options. -std::shared_ptr TlsCredentials( - const TlsCredentialsOptions& options); - -} // namespace experimental -} // namespace grpc_impl - -#endif // GRPCPP_SECURITY_CREDENTIALS_IMPL_H diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index f41c05d59f2..f6ee1caa3bf 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -57,11 +57,11 @@ struct SslServerCredentialsOptions { static inline std::shared_ptr SslServerCredentials( const SslServerCredentialsOptions& options) { - return ::grpc_impl::SslServerCredentials(options); + return ::grpc::SslServerCredentials(options); } static inline std::shared_ptr InsecureServerCredentials() { - return ::grpc_impl::InsecureServerCredentials(); + return ::grpc::InsecureServerCredentials(); } namespace experimental { @@ -71,18 +71,18 @@ typedef ::grpc_impl::experimental::AltsServerCredentialsOptions static inline std::shared_ptr AltsServerCredentials( const AltsServerCredentialsOptions& options) { - return ::grpc_impl::experimental::AltsServerCredentials(options); + return ::grpc::experimental::AltsServerCredentials(options); } static inline std::shared_ptr LocalServerCredentials( grpc_local_connect_type type) { - return ::grpc_impl::experimental::LocalServerCredentials(type); + return ::grpc::experimental::LocalServerCredentials(type); } /// Builds TLS ServerCredentials given TLS options. static inline std::shared_ptr TlsServerCredentials( - const ::grpc_impl::experimental::TlsCredentialsOptions& options) { - return ::grpc_impl::experimental::TlsServerCredentials(options); + const ::grpc::experimental::TlsCredentialsOptions& options) { + return ::grpc::experimental::TlsServerCredentials(options); } } // namespace experimental diff --git a/include/grpcpp/security/server_credentials_impl.h b/include/grpcpp/security/server_credentials_impl.h index efd7cf66759..51c32be14fd 100644 --- a/include/grpcpp/security/server_credentials_impl.h +++ b/include/grpcpp/security/server_credentials_impl.h @@ -82,7 +82,7 @@ std::shared_ptr LocalServerCredentials( /// Builds TLS ServerCredentials given TLS options. std::shared_ptr TlsServerCredentials( - const TlsCredentialsOptions& options); + const grpc::experimental::TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc_impl diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index d29e56eee40..27fcd9f91c6 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -36,7 +36,7 @@ typedef struct grpc_tls_server_authorization_check_config grpc_tls_server_authorization_check_config; typedef struct grpc_tls_credentials_options grpc_tls_credentials_options; -namespace grpc_impl { +namespace grpc { namespace experimental { /** TLS key materials config, wrapper for grpc_tls_key_materials_config. It is @@ -340,6 +340,6 @@ class TlsCredentialsOptions { }; } // namespace experimental -} // namespace grpc_impl +} // namespace grpc #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H diff --git a/include/grpcpp/support/channel_arguments_impl.h b/include/grpcpp/support/channel_arguments_impl.h index ca3188a9e75..699aa6c45c9 100644 --- a/include/grpcpp/support/channel_arguments_impl.h +++ b/include/grpcpp/support/channel_arguments_impl.h @@ -28,6 +28,7 @@ #include namespace grpc { +class SecureChannelCredentials; namespace testing { class ChannelArgumentsTest; } // namespace testing @@ -35,7 +36,6 @@ class ChannelArgumentsTest; namespace grpc_impl { -class SecureChannelCredentials; /// Options for channel creation. The user can use generic setters to pass /// key value pairs down to C channel creation code. For gRPC related options, @@ -126,7 +126,7 @@ class ChannelArguments { } private: - friend class grpc_impl::SecureChannelCredentials; + friend class grpc::SecureChannelCredentials; friend class grpc::testing::ChannelArgumentsTest; /// Default pointer argument operations. diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 6865758142a..10232a8c9bf 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -73,7 +73,7 @@ ClientContext::~ClientContext() { } void ClientContext::set_credentials( - const std::shared_ptr& creds) { + const std::shared_ptr& creds) { creds_ = creds; // If call_ is set, we have already created the call, and set the call // credentials. This should only be done before we have started the batch diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index c6041edcb36..a7fbc0b21f6 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -26,14 +26,14 @@ #include "src/cpp/client/create_channel_internal.h" -namespace grpc_impl { -std::shared_ptr CreateChannelImpl( +namespace grpc { +std::shared_ptr CreateChannel( const grpc::string& target, const std::shared_ptr& creds) { - return CreateCustomChannelImpl(target, creds, grpc::ChannelArguments()); + return CreateCustomChannel(target, creds, grpc::ChannelArguments()); } -std::shared_ptr CreateCustomChannelImpl( +std::shared_ptr CreateCustomChannel( const grpc::string& target, const std::shared_ptr& creds, const grpc::ChannelArguments& args) { @@ -82,4 +82,4 @@ std::shared_ptr CreateCustomChannelWithInterceptors( } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/credentials_cc.cc b/src/cpp/client/credentials_cc.cc index 62334bd9eba..9dfb2f491ca 100644 --- a/src/cpp/client/credentials_cc.cc +++ b/src/cpp/client/credentials_cc.cc @@ -19,7 +19,7 @@ #include #include -namespace grpc_impl { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; ChannelCredentials::ChannelCredentials() { g_gli_initializer.summon(); } @@ -30,4 +30,4 @@ CallCredentials::CallCredentials() { g_gli_initializer.summon(); } CallCredentials::~CallCredentials() {} -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/cronet_credentials.cc b/src/cpp/client/cronet_credentials.cc index f4ead14cde8..d09e2841279 100644 --- a/src/cpp/client/cronet_credentials.cc +++ b/src/cpp/client/cronet_credentials.cc @@ -55,10 +55,9 @@ class CronetChannelCredentialsImpl final : public ChannelCredentials { } void* engine_; }; -} // namespace grpc -namespace grpc_impl { + std::shared_ptr CronetChannelCredentials(void* engine) { return std::shared_ptr( new grpc::CronetChannelCredentialsImpl(engine)); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc index 0556fa0e50f..10fc356cc67 100644 --- a/src/cpp/client/insecure_credentials.cc +++ b/src/cpp/client/insecure_credentials.cc @@ -24,7 +24,7 @@ #include #include "src/cpp/client/create_channel_internal.h" -namespace grpc_impl { +namespace grpc { namespace { class InsecureChannelCredentialsImpl final : public ChannelCredentials { @@ -59,4 +59,4 @@ std::shared_ptr InsecureChannelCredentials() { new InsecureChannelCredentialsImpl()); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index b21d5102e23..38d888ba0d6 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -38,7 +38,7 @@ #include "src/cpp/client/create_channel_internal.h" #include "src/cpp/common/secure_auth_context.h" -namespace grpc_impl { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; SecureChannelCredentials::SecureChannelCredentials( @@ -387,9 +387,6 @@ std::shared_ptr MetadataCredentialsFromPlugin( c_plugin, GRPC_PRIVACY_AND_INTEGRITY, nullptr)); } -} // namespace grpc_impl - -namespace grpc { namespace { void DeleteWrapper(void* wrapper, grpc_error* /*ignored*/) { MetadataCredentialsPluginWrapper* w = diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 84852a47942..69eec1634b9 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -33,6 +32,9 @@ namespace grpc_impl { class Channel; +} // namespace grpc_impl + +namespace grpc { class SecureChannelCredentials final : public ChannelCredentials { public: @@ -85,10 +87,6 @@ grpc_sts_credentials_options StsCredentialsCppToCoreOptions( } // namespace experimental -} // namespace grpc_impl - -namespace grpc { - class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); diff --git a/src/cpp/common/tls_credentials_options.cc b/src/cpp/common/tls_credentials_options.cc index 8c6fd51c0cf..1ea08f0dc85 100644 --- a/src/cpp/common/tls_credentials_options.cc +++ b/src/cpp/common/tls_credentials_options.cc @@ -23,7 +23,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** TLS key materials config API implementation **/ @@ -340,4 +340,4 @@ TlsCredentialsOptions::TlsCredentialsOptions( TlsCredentialsOptions::~TlsCredentialsOptions() {} } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/common/tls_credentials_options_util.cc b/src/cpp/common/tls_credentials_options_util.cc index 2211460e664..51cc4e2aefa 100644 --- a/src/cpp/common/tls_credentials_options_util.cc +++ b/src/cpp/common/tls_credentials_options_util.cc @@ -21,7 +21,7 @@ #include #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** Converts the Cpp key materials to C key materials; this allocates memory for @@ -146,4 +146,4 @@ void TlsServerAuthorizationCheckArgDestroyContext(void* context) { } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/common/tls_credentials_options_util.h b/src/cpp/common/tls_credentials_options_util.h index 93e94562398..4ee04d15d7f 100644 --- a/src/cpp/common/tls_credentials_options_util.h +++ b/src/cpp/common/tls_credentials_options_util.h @@ -24,7 +24,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** The following function is exposed for testing purposes. **/ @@ -53,6 +53,6 @@ void TlsCredentialReloadArgDestroyContext(void* context); void TlsServerAuthorizationCheckArgDestroyContext(void* context); } // namespace experimental -} // namespace grpc_impl +} // namespace grpc #endif // GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index cf8dcd7d7c9..083c9620f6a 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -149,7 +149,7 @@ std::shared_ptr LocalServerCredentials( } std::shared_ptr TlsServerCredentials( - const TlsCredentialsOptions& options) { + const grpc::experimental::TlsCredentialsOptions& options) { grpc::GrpcLibraryCodegen init; return std::shared_ptr(new SecureServerCredentials( grpc_tls_server_credentials_create(options.c_credentials_options()))); diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 71d25f587a6..ac81820848a 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -940,7 +940,6 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ -include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/create_channel_posix_impl.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ @@ -1027,7 +1026,6 @@ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/credentials.h \ -include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 48dcb673dcb..b03fe0c91ad 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -940,7 +940,6 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ -include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/create_channel_posix_impl.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ @@ -1027,7 +1026,6 @@ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/auth_metadata_processor_impl.h \ include/grpcpp/security/credentials.h \ -include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ From 18cc2f6f341a6fa34212390dc0cb8937e11c5118 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Wed, 24 Jun 2020 21:24:01 -0700 Subject: [PATCH 04/45] Formatting fixes --- CMakeLists.txt | 2 -- Makefile | 2 -- gRPC-C++.podspec | 1 - include/grpcpp/impl/codegen/client_context_impl.h | 3 +-- include/grpcpp/support/channel_arguments_impl.h | 1 - 5 files changed, 1 insertion(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f7943e5e4c9..0214ce8fb2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2788,7 +2788,6 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h - include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/create_channel_posix_impl.h include/grpcpp/ext/health_check_service_server_builder_option.h @@ -3480,7 +3479,6 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h - include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/create_channel_posix_impl.h include/grpcpp/ext/health_check_service_server_builder_option.h diff --git a/Makefile b/Makefile index 4c69d6f5108..84a186e0a71 100644 --- a/Makefile +++ b/Makefile @@ -4985,7 +4985,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ - include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/create_channel_posix_impl.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ @@ -5682,7 +5681,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ - include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/create_channel_posix_impl.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index de37ca66dd1..b3526bc0332 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -84,7 +84,6 @@ Pod::Spec.new do |s| 'include/grpcpp/completion_queue.h', 'include/grpcpp/completion_queue_impl.h', 'include/grpcpp/create_channel.h', - 'include/grpcpp/create_channel_impl.h', 'include/grpcpp/create_channel_posix.h', 'include/grpcpp/create_channel_posix_impl.h', 'include/grpcpp/ext/health_check_service_server_builder_option.h', diff --git a/include/grpcpp/impl/codegen/client_context_impl.h b/include/grpcpp/impl/codegen/client_context_impl.h index c1ab794bfed..81fd1a01174 100644 --- a/include/grpcpp/impl/codegen/client_context_impl.h +++ b/include/grpcpp/impl/codegen/client_context_impl.h @@ -320,8 +320,7 @@ class ClientContext { /// It is legal to call this only before initial metadata is sent. /// /// \see https://grpc.io/docs/guides/auth.html - void set_credentials( - const std::shared_ptr& creds); + void set_credentials(const std::shared_ptr& creds); /// EXPERIMENTAL debugging API /// diff --git a/include/grpcpp/support/channel_arguments_impl.h b/include/grpcpp/support/channel_arguments_impl.h index 699aa6c45c9..36f48480d96 100644 --- a/include/grpcpp/support/channel_arguments_impl.h +++ b/include/grpcpp/support/channel_arguments_impl.h @@ -36,7 +36,6 @@ class ChannelArgumentsTest; namespace grpc_impl { - /// Options for channel creation. The user can use generic setters to pass /// key value pairs down to C channel creation code. For gRPC related options, /// concrete setters are provided. From bf551af394dc025825f38fc527b0aade58cf59c7 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 29 Jun 2020 13:02:01 -0700 Subject: [PATCH 05/45] Fix credentials test. --- test/cpp/client/credentials_test.cc | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index c8d2713140a..dd59394e59f 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -34,15 +34,15 @@ namespace { -typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; -typedef class ::grpc_impl::experimental::TlsCredentialReloadArg +typedef class ::grpc::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef struct ::grpc_impl::experimental::TlsCredentialReloadInterface +typedef struct ::grpc::experimental::TlsCredentialReloadInterface TlsCredentialReloadInterface; -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef struct ::grpc_impl::experimental::TlsServerAuthorizationCheckInterface +typedef struct ::grpc::experimental::TlsServerAuthorizationCheckInterface TlsServerAuthorizationCheckInterface; static void tls_credential_reload_callback( @@ -131,7 +131,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsCppToCore) { options.actor_token_path = "/foo/baz"; options.actor_token_type = "even_nicer_token_type"; grpc_sts_credentials_options core_opts = - grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); + grpc::experimental::StsCredentialsCppToCoreOptions(options); EXPECT_EQ(options.token_exchange_service_uri, core_opts.token_exchange_service_uri); EXPECT_EQ(options.resource, core_opts.resource); @@ -271,7 +271,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsFromEnv) { gpr_unsetenv("STS_CREDENTIALS"); } -typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) { @@ -304,9 +304,9 @@ TEST_F(CredentialsTest, TlsKeyMaterialsModifiers) { EXPECT_STREQ(list[0].cert_chain.c_str(), "cert_chain"); } -typedef class ::grpc_impl::experimental::TlsCredentialReloadArg +typedef class ::grpc::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig +typedef class ::grpc::experimental::TlsCredentialReloadConfig TlsCredentialReloadConfig; TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) { @@ -433,9 +433,9 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) { delete config.c_config(); } -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckConfig +typedef class ::grpc::experimental::TlsServerAuthorizationCheckConfig TlsServerAuthorizationCheckConfig; TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) { @@ -550,7 +550,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { delete config.c_config(); } -typedef class ::grpc_impl::experimental::TlsCredentialsOptions +typedef class ::grpc::experimental::TlsCredentialsOptions TlsCredentialsOptions; TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) { @@ -681,7 +681,7 @@ TEST_F(CredentialsTest, LoadTlsChannelCredentials) { TlsCredentialsOptions options = TlsCredentialsOptions( GRPC_TLS_SERVER_VERIFICATION, nullptr, credential_reload_config, server_authorization_check_config); - std::shared_ptr channel_credentials = + std::shared_ptr channel_credentials = grpc::experimental::TlsCredentials(options); GPR_ASSERT(channel_credentials.get() != nullptr); } From 59b41d50fa16c14fdb9cceef1d5fb2feb5566ea9 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 29 Jun 2020 14:37:52 -0700 Subject: [PATCH 06/45] Formatting fixes --- test/cpp/client/credentials_test.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index dd59394e59f..25e47eaf961 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -34,8 +34,7 @@ namespace { -typedef class ::grpc::experimental::TlsKeyMaterialsConfig - TlsKeyMaterialsConfig; +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; typedef class ::grpc::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; typedef struct ::grpc::experimental::TlsCredentialReloadInterface @@ -271,8 +270,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsFromEnv) { gpr_unsetenv("STS_CREDENTIALS"); } -typedef class ::grpc::experimental::TlsKeyMaterialsConfig - TlsKeyMaterialsConfig; +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) { std::shared_ptr config(new TlsKeyMaterialsConfig()); @@ -550,8 +548,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { delete config.c_config(); } -typedef class ::grpc::experimental::TlsCredentialsOptions - TlsCredentialsOptions; +typedef class ::grpc::experimental::TlsCredentialsOptions TlsCredentialsOptions; TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) { std::shared_ptr key_materials_config( From 0963497181222c0efbbf7918fd158287ae97c763 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 29 Jun 2020 17:07:56 -0700 Subject: [PATCH 07/45] Fix fetch oauth2 test --- test/core/security/fetch_oauth2.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 1aa999758b0..393c0a3e511 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -26,7 +26,7 @@ #include #include -#include "grpcpp/security/credentials_impl.h" +#include "grpcpp/security/credentials.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/security/credentials/credentials.h" @@ -36,10 +36,10 @@ #include "test/core/util/cmdline.h" static grpc_call_credentials* create_sts_creds(const char* json_file_path) { - grpc_impl::experimental::StsCredentialsOptions options; + grpc::experimental::StsCredentialsOptions options; if (strlen(json_file_path) == 0) { auto status = - grpc_impl::experimental::StsCredentialsOptionsFromEnv(&options); + grpc::experimental::StsCredentialsOptionsFromEnv(&options); if (!status.ok()) { gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); return nullptr; @@ -48,7 +48,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { grpc_slice sts_options_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(json_file_path, 1, &sts_options_slice))); - auto status = grpc_impl::experimental::StsCredentialsOptionsFromJson( + auto status = grpc::experimental::StsCredentialsOptionsFromJson( reinterpret_cast(GRPC_SLICE_START_PTR(sts_options_slice)), &options); gpr_slice_unref(sts_options_slice); @@ -58,7 +58,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { } } grpc_sts_credentials_options opts = - grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); + grpc::experimental::StsCredentialsCppToCoreOptions(options); grpc_call_credentials* result = grpc_sts_credentials_create(&opts, nullptr); return result; } From fa0c73146c0a064355f238270b8dee6210d3724d Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 29 Jun 2020 17:28:11 -0700 Subject: [PATCH 08/45] Fix formatting issue --- test/core/security/fetch_oauth2.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 393c0a3e511..99d7c76d0d3 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -38,8 +38,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { grpc::experimental::StsCredentialsOptions options; if (strlen(json_file_path) == 0) { - auto status = - grpc::experimental::StsCredentialsOptionsFromEnv(&options); + auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); if (!status.ok()) { gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); return nullptr; From decb53ccc0dbe2952d69a63924a99bcd59e89945 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 13 Jul 2020 11:05:02 -0700 Subject: [PATCH 09/45] Fix build error --- include/grpcpp/security/credentials.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 851f33f5959..b0da6650b6b 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -280,11 +280,8 @@ struct StsCredentialsOptions { grpc::string actor_token_type; // Optional. }; -static inline grpc::Status StsCredentialsOptionsFromJson( - const std::string& json_string, StsCredentialsOptions* options) { - return ::grpc::experimental::StsCredentialsOptionsFromJson(json_string, - options); -} +grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, + StsCredentialsOptions* options); /// Creates STS credentials options from the $STS_CREDENTIALS environment /// variable. This environment variable points to the path of a JSON file From e6a6fdb3132d687e504b294e232384225695e63f Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 13 Jul 2020 13:04:56 -0700 Subject: [PATCH 10/45] Fix secure test --- include/grpcpp/security/server_credentials.h | 24 ++++--------------- src/cpp/server/insecure_server_credentials.cc | 4 ++-- src/cpp/server/secure_server_credentials.cc | 4 ++-- src/cpp/server/secure_server_credentials.h | 13 ++-------- 4 files changed, 11 insertions(+), 34 deletions(-) diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index 7e4381af487..29afc7d2744 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -55,35 +55,21 @@ struct SslServerCredentialsOptions { grpc_ssl_client_certificate_request_type client_certificate_request; }; -static inline std::shared_ptr SslServerCredentials( - const SslServerCredentialsOptions& options) { - return ::grpc::SslServerCredentials(options); -} +std::shared_ptr SslServerCredentials(const SslServerCredentialsOptions& options); -static inline std::shared_ptr InsecureServerCredentials() { - return ::grpc::InsecureServerCredentials(); -} +std::shared_ptr InsecureServerCredentials(); namespace experimental { typedef ::grpc_impl::experimental::AltsServerCredentialsOptions AltsServerCredentialsOptions; -static inline std::shared_ptr AltsServerCredentials( - const AltsServerCredentialsOptions& options) { - return ::grpc::experimental::AltsServerCredentials(options); -} +std::shared_ptr AltsServerCredentials(const AltsServerCredentialsOptions& options); -static inline std::shared_ptr LocalServerCredentials( - grpc_local_connect_type type) { - return ::grpc::experimental::LocalServerCredentials(type); -} +std::shared_ptr LocalServerCredentials(grpc_local_connect_type type); /// Builds TLS ServerCredentials given TLS options. -static inline std::shared_ptr TlsServerCredentials( - const ::grpc::experimental::TlsCredentialsOptions& options) { - return ::grpc::experimental::TlsServerCredentials(options); -} +std::shared_ptr TlsServerCredentials(const ::grpc::experimental::TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc index bc908920b8d..04e5435efb9 100644 --- a/src/cpp/server/insecure_server_credentials.cc +++ b/src/cpp/server/insecure_server_credentials.cc @@ -21,7 +21,7 @@ #include #include -namespace grpc_impl { +namespace grpc { namespace { class InsecureServerCredentialsImpl final : public ServerCredentials { public: @@ -41,4 +41,4 @@ std::shared_ptr InsecureServerCredentials() { new InsecureServerCredentialsImpl()); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index a7eb7a1505c..48fb3ad9f34 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -94,7 +94,7 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( } // namespace grpc -namespace grpc_impl { +namespace grpc { int SecureServerCredentials::AddPortToServer(const std::string& addr, grpc_server* server) { @@ -156,4 +156,4 @@ std::shared_ptr TlsServerCredentials( } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/server/secure_server_credentials.h b/src/cpp/server/secure_server_credentials.h index 9e9e33579f0..407d70766b5 100644 --- a/src/cpp/server/secure_server_credentials.h +++ b/src/cpp/server/secure_server_credentials.h @@ -28,14 +28,9 @@ #include "src/cpp/server/thread_pool_interface.h" -namespace grpc_impl { - -class SecureServerCredentials; -} // namespace grpc_impl - namespace grpc { -typedef ::grpc_impl::SecureServerCredentials SecureServerCredentials; +class SecureServerCredentials; class AuthMetadataProcessorAyncWrapper final { public: @@ -61,10 +56,6 @@ class AuthMetadataProcessorAyncWrapper final { std::shared_ptr processor_; }; -} // namespace grpc - -namespace grpc_impl { - class SecureServerCredentials final : public ServerCredentials { public: explicit SecureServerCredentials(grpc_server_credentials* creds) @@ -83,6 +74,6 @@ class SecureServerCredentials final : public ServerCredentials { std::unique_ptr processor_; }; -} // namespace grpc_impl +} // namespace grpc #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H From 3b2d26daacc4b9b78b4d346489b5d19db2a42be4 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Mon, 13 Jul 2020 13:19:18 -0700 Subject: [PATCH 11/45] Fix formatting --- include/grpcpp/security/server_credentials.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index 29afc7d2744..1223b10978e 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -55,7 +55,8 @@ struct SslServerCredentialsOptions { grpc_ssl_client_certificate_request_type client_certificate_request; }; -std::shared_ptr SslServerCredentials(const SslServerCredentialsOptions& options); +std::shared_ptr SslServerCredentials( + const SslServerCredentialsOptions& options); std::shared_ptr InsecureServerCredentials(); @@ -64,12 +65,15 @@ namespace experimental { typedef ::grpc_impl::experimental::AltsServerCredentialsOptions AltsServerCredentialsOptions; -std::shared_ptr AltsServerCredentials(const AltsServerCredentialsOptions& options); +std::shared_ptr AltsServerCredentials( + const AltsServerCredentialsOptions& options); -std::shared_ptr LocalServerCredentials(grpc_local_connect_type type); +std::shared_ptr LocalServerCredentials( + grpc_local_connect_type type); /// Builds TLS ServerCredentials given TLS options. -std::shared_ptr TlsServerCredentials(const ::grpc::experimental::TlsCredentialsOptions& options); +std::shared_ptr TlsServerCredentials( + const ::grpc::experimental::TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc From bec17c1dd34bcf25c9958bbb3747052703105be3 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 14 Jul 2020 14:09:09 -0700 Subject: [PATCH 12/45] Avoid unused variables --- test/cpp/end2end/interceptors_util.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/cpp/end2end/interceptors_util.cc b/test/cpp/end2end/interceptors_util.cc index 96295fb9ae2..05e49532b2c 100644 --- a/test/cpp/end2end/interceptors_util.cc +++ b/test/cpp/end2end/interceptors_util.cc @@ -114,7 +114,7 @@ void MakeAsyncCQCall(const std::shared_ptr& channel) { EXPECT_TRUE(recv_status.ok()); } -void MakeAsyncCQClientStreamingCall(const std::shared_ptr& channel) { +void MakeAsyncCQClientStreamingCall(const std::shared_ptr& /*channel*/) { // TODO(yashykt) : Fill this out } @@ -146,7 +146,8 @@ void MakeAsyncCQServerStreamingCall(const std::shared_ptr& channel) { EXPECT_TRUE(recv_status.ok()); } -void MakeAsyncCQBidiStreamingCall(const std::shared_ptr& channel) { +void MakeAsyncCQBidiStreamingCall( + const std::shared_ptr& /*channel*/) { // TODO(yashykt) : Fill this out } From 612a3dfa10e37b8bca4c37edec8610ef9fe750dc Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 14 Jul 2020 14:10:54 -0700 Subject: [PATCH 13/45] clang-format --- test/cpp/end2end/interceptors_util.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/cpp/end2end/interceptors_util.cc b/test/cpp/end2end/interceptors_util.cc index 05e49532b2c..b8c92da5a3b 100644 --- a/test/cpp/end2end/interceptors_util.cc +++ b/test/cpp/end2end/interceptors_util.cc @@ -114,7 +114,8 @@ void MakeAsyncCQCall(const std::shared_ptr& channel) { EXPECT_TRUE(recv_status.ok()); } -void MakeAsyncCQClientStreamingCall(const std::shared_ptr& /*channel*/) { +void MakeAsyncCQClientStreamingCall( + const std::shared_ptr& /*channel*/) { // TODO(yashykt) : Fill this out } @@ -146,8 +147,7 @@ void MakeAsyncCQServerStreamingCall(const std::shared_ptr& channel) { EXPECT_TRUE(recv_status.ok()); } -void MakeAsyncCQBidiStreamingCall( - const std::shared_ptr& /*channel*/) { +void MakeAsyncCQBidiStreamingCall(const std::shared_ptr& /*channel*/) { // TODO(yashykt) : Fill this out } From 1bc973bd4820d327d7d64fb0f7ef3c75badc355e Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Fri, 17 Jul 2020 13:39:55 -0700 Subject: [PATCH 14/45] Uses sources.json from BoringSSL This change undoes some hackiness that relied on specifics of the BoringSSL build system to generate source files. With the latest github mirror of BoringSSL exports a sources.json that lists all source code files. This change makes use of that file. --- src/boringssl/gen_build_yaml.py | 59 ++++++++------------------------- 1 file changed, 14 insertions(+), 45 deletions(-) diff --git a/src/boringssl/gen_build_yaml.py b/src/boringssl/gen_build_yaml.py index b54f53df095..7635f3b7970 100755 --- a/src/boringssl/gen_build_yaml.py +++ b/src/boringssl/gen_build_yaml.py @@ -13,24 +13,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function -import shutil -import sys +import json import os +import sys import yaml -sys.dont_write_bytecode = True - -boring_ssl_root = os.path.abspath( +sources_path = os.path.abspath( os.path.join(os.path.dirname(sys.argv[0]), - '../../third_party/boringssl-with-bazel/src')) -sys.path.append(os.path.join(boring_ssl_root, 'util')) - -try: - import generate_build_files -except ImportError: - print(yaml.dump({})) - sys.exit() + '../../third_party/boringssl-with-bazel/sources.json')) +with open(sources_path, 'r') as s: + sources = json.load(s) def map_dir(filename): @@ -38,18 +30,19 @@ def map_dir(filename): class Grpc(object): - """Implements a "platform" in the sense of boringssl's generate_build_files.py""" - yaml = None + """ Adapter for boring-SSL json sources files. """ - def WriteFiles(self, files, asm_outputs): - test_binaries = ['ssl_test', 'crypto_test'] + def __init__(self, sources): + self.yaml = None + self.WriteFiles(sources) + def WriteFiles(self, files): + test_binaries = ['ssl_test', 'crypto_test'] self.yaml = { '#': 'generated with src/boringssl/gen_build_yaml.py', 'raw_boringssl_build_output_for_debugging': { 'files': files, - 'asm_outputs': asm_outputs, }, 'libs': [ { @@ -120,29 +113,5 @@ class Grpc(object): } -os.chdir(os.path.dirname(sys.argv[0])) -os.mkdir('src') -try: - for f in os.listdir(boring_ssl_root): - os.symlink(os.path.join(boring_ssl_root, f), os.path.join('src', f)) - - grpc_platform = Grpc() - # We use a hack to run boringssl's util/generate_build_files.py as part of this script. - # The call will populate "grpc_platform" with boringssl's source file metadata. - # As a side effect this script generates err_data.c and crypto_test_data.cc (requires golang) - # Both of these files are already available under third_party/boringssl-with-bazel - # so we don't need to generate them again, but there's no option to disable that behavior. - # - crypto_test_data.cc is required to run boringssl_crypto_test but we already - # use the copy under third_party/boringssl-with-bazel so we just delete it - # - err_data.c is already under third_party/boringssl-with-bazel so we just delete it - generate_build_files.main([grpc_platform]) - - print(yaml.dump(grpc_platform.yaml)) - -finally: - # we don't want err_data.c and crypto_test_data.cc (see comment above) - if os.path.exists('err_data.c'): - os.remove('err_data.c') - if os.path.exists('crypto_test_data.cc'): - os.remove('crypto_test_data.cc') - shutil.rmtree('src') +grpc_platform = Grpc(sources) +print(yaml.dump(grpc_platform.yaml)) From b3d1f2a4f8763ea5567ded2b37bdb16d259e64dd Mon Sep 17 00:00:00 2001 From: Hannah Shi Date: Fri, 17 Jul 2020 22:34:35 +0000 Subject: [PATCH 15/45] avoid destroy channel more than once --- src/php/ext/grpc/channel.c | 2 +- src/php/ext/grpc/php_grpc.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/php/ext/grpc/channel.c b/src/php/ext/grpc/channel.c index 47483812b25..e9b6d67f817 100644 --- a/src/php/ext/grpc/channel.c +++ b/src/php/ext/grpc/channel.c @@ -50,7 +50,7 @@ extern HashTable grpc_persistent_list; extern HashTable grpc_target_upper_bound_map; void free_grpc_channel_wrapper(grpc_channel_wrapper* channel, bool free_channel) { - if (free_channel) { + if (free_channel && channel->wrapped) { grpc_channel_destroy(channel->wrapped); channel->wrapped = NULL; } diff --git a/src/php/ext/grpc/php_grpc.c b/src/php/ext/grpc/php_grpc.c index f567d8c59c3..01764a71202 100644 --- a/src/php/ext/grpc/php_grpc.c +++ b/src/php/ext/grpc/php_grpc.c @@ -159,6 +159,7 @@ void destroy_grpc_channels() { wrapped_channel.wrapper = le->channel; grpc_channel_wrapper *channel = wrapped_channel.wrapper; grpc_channel_destroy(channel->wrapped); + channel->wrapped = NULL; PHP_GRPC_HASH_FOREACH_END() } From 16fc98f55d4105a0e90aaecf5d997ad73ed853aa Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 22 Jul 2020 03:13:51 -0700 Subject: [PATCH 16/45] Convert multi-line comments to single line comments in chttp2_transport.cc --- .../chttp2/transport/chttp2_transport.cc | 310 +++++++++--------- 1 file changed, 153 insertions(+), 157 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 6d25f5c7724..74324a651f6 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -1,20 +1,18 @@ -/* - * - * Copyright 2018 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. - * - */ +// +// Copyright 2018 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. +// #include @@ -103,7 +101,7 @@ grpc_core::TraceFlag grpc_keepalive_trace(false, "http_keepalive"); grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_refcount(false, "chttp2_refcount"); -/* forward declarations of various callbacks that we'll build closures around */ +// forward declarations of various callbacks that we'll build closures around static void write_action_begin_locked(void* t, grpc_error* error); static void write_action(void* t, grpc_error* error); static void write_action_end(void* t, grpc_error* error); @@ -115,14 +113,14 @@ static void continue_read_action_locked(grpc_chttp2_transport* t); static void complete_fetch(void* gs, grpc_error* error); static void complete_fetch_locked(void* gs, grpc_error* error); -/** Set a transport level setting, and push it to our peer */ +// Set a transport level setting, and push it to our peer static void queue_setting_update(grpc_chttp2_transport* t, grpc_chttp2_setting_id id, uint32_t value); static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, grpc_error* error); -/** Start new streams that have been created if we can */ +// Start new streams that have been created if we can static void maybe_start_some_streams(grpc_chttp2_transport* t); static void connectivity_state_set(grpc_chttp2_transport* t, @@ -154,7 +152,7 @@ static void send_ping_locked(grpc_chttp2_transport* t, grpc_closure* on_complete); static void retry_initiate_ping_locked(void* tp, grpc_error* error); -/** keepalive-relevant functions */ +// keepalive-relevant functions static void init_keepalive_ping(void* arg, grpc_error* error); static void init_keepalive_ping_locked(void* arg, grpc_error* error); static void start_keepalive_ping(void* arg, grpc_error* error); @@ -170,9 +168,9 @@ static void reset_byte_stream(void* arg, grpc_error* error); // GRPC_EXPERIMENTAL_DISABLE_FLOW_CONTROL bool g_flow_control_enabled = true; -/******************************************************************************* - * CONSTRUCTION/DESTRUCTION/REFCOUNTING - */ +// +// CONSTRUCTION/DESTRUCTION/REFCOUNTING +// grpc_chttp2_transport::~grpc_chttp2_transport() { size_t i; @@ -231,7 +229,7 @@ grpc_chttp2_transport::~grpc_chttp2_transport() { static const grpc_transport_vtable* get_vtable(void); -/* Returns whether bdp is enabled */ +// Returns whether bdp is enabled static bool read_channel_args(grpc_chttp2_transport* t, const grpc_channel_args* channel_args, bool is_client) { @@ -429,8 +427,8 @@ static void init_keepalive_pings_if_enabled(grpc_chttp2_transport* t) { grpc_core::ExecCtx::Get()->Now() + t->keepalive_time, &t->init_keepalive_ping_locked); } else { - /* Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no - inflight keeaplive timers */ + // Use GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED to indicate there are no + // inflight keeaplive timers t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED; } } @@ -451,11 +449,11 @@ grpc_chttp2_transport::grpc_chttp2_transport( GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) == GRPC_CHTTP2_CLIENT_CONNECT_STRLEN); base.vtable = get_vtable(); - /* 8 is a random stab in the dark as to a good initial size: it's small enough - that it shouldn't waste memory for infrequently used connections, yet - large enough that the exponential growth should happen nicely when it's - needed. - TODO(ctiller): tune this */ + // 8 is a random stab in the dark as to a good initial size: it's small enough + // that it shouldn't waste memory for infrequently used connections, yet + // large enough that the exponential growth should happen nicely when it's + // needed. + // TODO(ctiller): tune this grpc_chttp2_stream_map_init(&stream_map, 8); grpc_slice_buffer_init(&read_buffer); @@ -466,7 +464,7 @@ grpc_chttp2_transport::grpc_chttp2_transport( } grpc_chttp2_hpack_compressor_init(&hpack_compressor); grpc_slice_buffer_init(&qbuf); - /* copy in initial settings to all setting sets */ + // copy in initial settings to all setting sets size_t i; int j; for (i = 0; i < GRPC_CHTTP2_NUM_SETTINGS; i++) { @@ -477,7 +475,7 @@ grpc_chttp2_transport::grpc_chttp2_transport( grpc_chttp2_hpack_parser_init(&hpack_parser); grpc_chttp2_goaway_parser_init(&goaway_parser); - /* configure http2 the way we like it */ + // configure http2 the way we like it if (is_client) { queue_setting_update(this, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0); queue_setting_update(this, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0); @@ -503,7 +501,7 @@ grpc_chttp2_transport::grpc_chttp2_transport( enable_bdp = false; } - /* No pings allowed before receiving a header or data frame. */ + // No pings allowed before receiving a header or data frame. ping_state.pings_before_data_required = 0; ping_state.is_delayed_ping_timer_set = false; ping_state.last_ping_sent_time = GRPC_MILLIS_INF_PAST; @@ -579,11 +577,11 @@ static void close_transport_locked(grpc_chttp2_transport* t, break; case GRPC_CHTTP2_KEEPALIVE_STATE_DYING: case GRPC_CHTTP2_KEEPALIVE_STATE_DISABLED: - /* keepalive timers are not set in these two states */ + // keepalive timers are not set in these two states break; } - /* flush writable stream list to avoid dangling references */ + // flush writable stream list to avoid dangling references grpc_chttp2_stream* s; while (grpc_chttp2_list_pop_writable_stream(t, &s)) { GRPC_CHTTP2_STREAM_UNREF(s, "chttp2_writing:close"); @@ -616,9 +614,9 @@ void grpc_chttp2_stream_unref(grpc_chttp2_stream* s) { #endif grpc_chttp2_stream::Reffer::Reffer(grpc_chttp2_stream* s) { - /* We reserve one 'active stream' that's dropped when the stream is - read-closed. The others are for Chttp2IncomingByteStreams that are - actively reading */ + // We reserve one 'active stream' that's dropped when the stream is + // read-closed. The others are for Chttp2IncomingByteStreams that are + // actively reading GRPC_CHTTP2_STREAM_REF(s, "chttp2"); GRPC_CHTTP2_REF_TRANSPORT(s->t, "stream"); } @@ -774,9 +772,9 @@ grpc_chttp2_stream* grpc_chttp2_parsing_accept_stream(grpc_chttp2_transport* t, return accepting; } -/******************************************************************************* - * OUTPUT PROCESSING - */ +// +// OUTPUT PROCESSING +// static const char* write_state_name(grpc_chttp2_write_state st) { switch (st) { @@ -797,12 +795,12 @@ static void set_write_state(grpc_chttp2_transport* t, t->is_client ? "CLIENT" : "SERVER", t->peer_string, write_state_name(t->write_state), write_state_name(st), reason)); t->write_state = st; - /* If the state is being reset back to idle, it means a write was just - * finished. Make sure all the run_after_write closures are scheduled. - * - * This is also our chance to close the transport if the transport was marked - * to be closed after all writes finish (for example, if we received a go-away - * from peer while we had some pending writes) */ + // If the state is being reset back to idle, it means a write was just + // finished. Make sure all the run_after_write closures are scheduled. + // + // This is also our chance to close the transport if the transport was marked + // to be closed after all writes finish (for example, if we received a go-away + // from peer while we had some pending writes) if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) { grpc_core::ExecCtx::RunList(DEBUG_LOCATION, &t->run_after_write); if (t->close_transport_on_writes_finished != nullptr) { @@ -889,22 +887,22 @@ void grpc_chttp2_initiate_write(grpc_chttp2_transport* t, set_write_state(t, GRPC_CHTTP2_WRITE_STATE_WRITING, grpc_chttp2_initiate_write_reason_string(reason)); GRPC_CHTTP2_REF_TRANSPORT(t, "writing"); - /* Note that the 'write_action_begin_locked' closure is being scheduled - * on the 'finally_scheduler' of t->combiner. This means that - * 'write_action_begin_locked' is called only *after* all the other - * closures (some of which are potentially initiating more writes on the - * transport) are executed on the t->combiner. - * - * The reason for scheduling on finally_scheduler is to make sure we batch - * as many writes as possible. 'write_action_begin_locked' is the function - * that gathers all the relevant bytes (which are at various places in the - * grpc_chttp2_transport structure) and append them to 'outbuf' field in - * grpc_chttp2_transport thereby batching what would have been potentially - * multiple write operations. - * - * Also, 'write_action_begin_locked' only gathers the bytes into outbuf. - * It does not call the endpoint to write the bytes. That is done by the - * 'write_action' (which is scheduled by 'write_action_begin_locked') */ + // Note that the 'write_action_begin_locked' closure is being scheduled + // on the 'finally_scheduler' of t->combiner. This means that + // 'write_action_begin_locked' is called only *after* all the other + // closures (some of which are potentially initiating more writes on the + // transport) are executed on the t->combiner. + // + // The reason for scheduling on finally_scheduler is to make sure we batch + // as many writes as possible. 'write_action_begin_locked' is the function + // that gathers all the relevant bytes (which are at various places in the + // grpc_chttp2_transport structure) and append them to 'outbuf' field in + // grpc_chttp2_transport thereby batching what would have been potentially + // multiple write operations. + // + // Also, 'write_action_begin_locked' only gathers the bytes into outbuf. + // It does not call the endpoint to write the bytes. That is done by the + // 'write_action' (which is scheduled by 'write_action_begin_locked') t->combiner->FinallyRun( GRPC_CLOSURE_INIT(&t->write_action_begin_locked, write_action_begin_locked, t, nullptr), @@ -956,9 +954,9 @@ static void write_action_begin_locked(void* gt, grpc_error* /*error_ignored*/) { write_action(t, GRPC_ERROR_NONE); if (t->reading_paused_on_pending_induced_frames) { GPR_ASSERT(t->num_pending_induced_frames == 0); - /* We had paused reading, because we had many induced frames (SETTINGS - * ACK, PINGS ACK and RST_STREAMS) pending in t->qbuf. Now that we have - * been able to flush qbuf, we can resume reading. */ + // We had paused reading, because we had many induced frames (SETTINGS + // ACK, PINGS ACK and RST_STREAMS) pending in t->qbuf. Now that we have + // been able to flush qbuf, we can resume reading. GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_INFO, "transport %p : Resuming reading after being paused due to too " @@ -993,8 +991,8 @@ static void write_action_end(void* tp, grpc_error* error) { GRPC_ERROR_REF(error)); } -/* Callback from the grpc_endpoint after bytes have been written by calling - * sendmsg */ +// Callback from the grpc_endpoint after bytes have been written by calling +// sendmsg static void write_action_end_locked(void* tp, grpc_error* error) { GPR_TIMER_SCOPE("terminate_writing_with_lock", 0); grpc_chttp2_transport* t = static_cast(tp); @@ -1080,16 +1078,16 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, GRPC_CHTTP2_IF_TRACING( gpr_log(GPR_INFO, "transport %p got goaway with last stream id %d", t, last_stream_id)); - /* We want to log this irrespective of whether http tracing is enabled if we - * received a GOAWAY with a non NO_ERROR code. */ + // We want to log this irrespective of whether http tracing is enabled if we + // received a GOAWAY with a non NO_ERROR code. if (goaway_error != GRPC_HTTP2_NO_ERROR) { gpr_log(GPR_INFO, "%s: Got goaway [%d] err=%s", t->peer_string, goaway_error, grpc_error_string(t->goaway_error)); } - /* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug - * data equal to "too_many_pings", it should log the occurrence at a log level - * that is enabled by default and double the configured KEEPALIVE_TIME used - * for new connections on that channel. */ + // When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug + // data equal to "too_many_pings", it should log the occurrence at a log level + // that is enabled by default and double the configured KEEPALIVE_TIME used + // for new connections on that channel. if (GPR_UNLIKELY(t->is_client && goaway_error == GRPC_HTTP2_ENHANCE_YOUR_CALM && grpc_slice_str_cmp(goaway_text, "too_many_pings") == 0)) { @@ -1105,14 +1103,14 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t, : static_cast(current_keepalive_time_ms * KEEPALIVE_TIME_BACKOFF_MULTIPLIER); } - /* lie: use transient failure from the transport to indicate goaway has been - * received */ + // lie: use transient failure from the transport to indicate goaway has been + // received connectivity_state_set(t, GRPC_CHANNEL_TRANSIENT_FAILURE, "got_goaway"); } static void maybe_start_some_streams(grpc_chttp2_transport* t) { grpc_chttp2_stream* s; - /* cancel out streams that haven't yet started if we have received a GOAWAY */ + // cancel out streams that haven't yet started if we have received a GOAWAY if (t->goaway_error != GRPC_ERROR_NONE) { while (grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) { grpc_chttp2_cancel_stream( @@ -1123,14 +1121,14 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) { } return; } - /* start streams where we have free grpc_chttp2_stream ids and free - * concurrency */ + // start streams where we have free grpc_chttp2_stream ids and free + // * concurrency while (t->next_stream_id <= MAX_CLIENT_STREAM_ID && grpc_chttp2_stream_map_size(&t->stream_map) < t->settings[GRPC_PEER_SETTINGS] [GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] && grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) { - /* safe since we can't (legally) be parsing this stream yet */ + // safe since we can't (legally) be parsing this stream yet GRPC_CHTTP2_IF_TRACING(gpr_log( GPR_INFO, "HTTP:%s: Transport %p allocating new grpc_chttp2_stream %p to id %d", @@ -1150,7 +1148,7 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) { grpc_chttp2_mark_stream_writable(t, s); grpc_chttp2_initiate_write(t, GRPC_CHTTP2_INITIATE_WRITE_START_NEW_STREAM); } - /* cancel out streams that will never be started */ + // cancel out streams that will never be started if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) { while (grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) { grpc_chttp2_cancel_stream( @@ -1162,12 +1160,12 @@ static void maybe_start_some_streams(grpc_chttp2_transport* t) { } } -/* Flag that this closure barrier may be covering a write in a pollset, and so - we should not complete this closure until we can prove that the write got - scheduled */ +// Flag that this closure barrier may be covering a write in a pollset, and so +// we should not complete this closure until we can prove that the write got +// scheduled #define CLOSURE_BARRIER_MAY_COVER_WRITE (1 << 0) -/* First bit of the reference count, stored in the high order bits (with the low - bits being used for flags defined above) */ +// First bit of the reference count, stored in the high order bits (with the low +// bits being used for flags defined above) #define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16) static grpc_closure* add_closure_barrier(grpc_closure* closure) { @@ -1259,7 +1257,7 @@ static void continue_fetching_send_locked(grpc_chttp2_transport* t, grpc_chttp2_stream* s) { for (;;) { if (s->fetching_send_message == nullptr) { - /* Stream was cancelled before message fetch completed */ + // Stream was cancelled before message fetch completed abort(); /* TODO(ctiller): what cleanup here? */ return; /* early out */ } @@ -1389,7 +1387,7 @@ static void perform_stream_op_locked(void* stream_op, GPR_ASSERT(s->send_initial_metadata_finished == nullptr); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; - /* Identify stream compression */ + // Identify stream compression if (op_payload->send_initial_metadata.send_initial_metadata->idx.named .content_encoding == nullptr || grpc_stream_compression_method_parse( @@ -1562,8 +1560,8 @@ static void perform_stream_op_locked(void* stream_op, "stream was closed"), "send_trailing_metadata_finished"); } else if (s->id != 0) { - /* TODO(ctiller): check if there's flow control for any outstanding - bytes before going writable */ + // TODO(ctiller): check if there's flow control for any outstanding + // bytes before going writable grpc_chttp2_mark_stream_writable(t, s); grpc_chttp2_initiate_write( t, GRPC_CHTTP2_INITIATE_WRITE_SEND_TRAILING_METADATA); @@ -1665,8 +1663,8 @@ static void perform_stream_op(grpc_transport* gt, grpc_stream* gs, } static void cancel_pings(grpc_chttp2_transport* t, grpc_error* error) { - /* callback remaining pings: they're not allowed to call into the transport, - and maybe they hold resources that need to be freed */ + // callback remaining pings: they're not allowed to call into the transport, + // and maybe they hold resources that need to be freed grpc_chttp2_ping_queue* pq = &t->ping_queue; GPR_ASSERT(error != GRPC_ERROR_NONE); for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) { @@ -1692,11 +1690,9 @@ static void send_ping_locked(grpc_chttp2_transport* t, GRPC_ERROR_NONE); } -/* - * Specialized form of send_ping_locked for keepalive ping. If there is already - * a ping in progress, the keepalive ping would piggyback onto that ping, - * instead of waiting for that ping to complete and then starting a new ping. - */ +// Specialized form of send_ping_locked for keepalive ping. If there is already +// a ping in progress, the keepalive ping would piggyback onto that ping, +// instead of waiting for that ping to complete and then starting a new ping. static void send_keepalive_ping_locked(grpc_chttp2_transport* t) { if (t->closed_with_error != GRPC_ERROR_NONE) { t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked, @@ -1710,7 +1706,7 @@ static void send_keepalive_ping_locked(grpc_chttp2_transport* t) { } grpc_chttp2_ping_queue* pq = &t->ping_queue; if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_INFLIGHT])) { - /* There is a ping in flight. Add yourself to the inflight closure list. */ + // There is a ping in flight. Add yourself to the inflight closure list. t->combiner->Run(GRPC_CLOSURE_INIT(&t->start_keepalive_ping_locked, start_keepalive_ping_locked, t, nullptr), GRPC_ERROR_REF(t->closed_with_error)); @@ -1765,7 +1761,7 @@ void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) { } static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) { - /* We want to log this irrespective of whether http tracing is enabled */ + // We want to log this irrespective of whether http tracing is enabled gpr_log(GPR_INFO, "%s: Sending goaway err=%s", t->peer_string, grpc_error_string(error)); t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; @@ -1787,7 +1783,7 @@ void grpc_chttp2_add_ping_strike(grpc_chttp2_transport* t) { grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"), GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); - /*The transport will be closed after the write is done */ + // The transport will be closed after the write is done close_transport_locked( t, grpc_error_set_int( GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"), @@ -1862,9 +1858,9 @@ static void perform_transport_op(grpc_transport* gt, grpc_transport_op* op) { GRPC_ERROR_NONE); } -/******************************************************************************* - * INPUT PROCESSING - GENERAL - */ +// +// INPUT PROCESSING - GENERAL +// void grpc_chttp2_maybe_complete_recv_initial_metadata( grpc_chttp2_transport* /*t*/, grpc_chttp2_stream* s) { @@ -1984,8 +1980,8 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_chttp2_transport* t, s->unprocessed_incoming_frames_buffer.length > 0; if (s->read_closed && s->frame_storage.length > 0 && !pending_data && !s->seen_error && s->recv_trailing_metadata_finished != nullptr) { - /* Maybe some SYNC_FLUSH data is left in frame_storage. Consume them and - * maybe decompress the next 5 bytes in the stream. */ + // Maybe some SYNC_FLUSH data is left in frame_storage. Consume them and + // maybe decompress the next 5 bytes in the stream. if (s->stream_decompression_method == GRPC_STREAM_COMPRESSION_IDENTITY_DECOMPRESS) { grpc_slice_buffer_move_first( @@ -2107,12 +2103,12 @@ void grpc_chttp2_fake_status(grpc_chttp2_transport* t, grpc_chttp2_stream* s, if (status != GRPC_STATUS_OK) { s->seen_error = true; } - /* stream_global->recv_trailing_metadata_finished gives us a - last chance replacement: we've received trailing metadata, - but something more important has become available to signal - to the upper layers - drop what we've got, and then publish - what we want - which is safe because we haven't told anyone - about the metadata yet */ + // stream_global->recv_trailing_metadata_finished gives us a + // last chance replacement: we've received trailing metadata, + // but something more important has become available to signal + // to the upper layers - drop what we've got, and then publish + // what we want - which is safe because we haven't told anyone + // about the metadata yet if (s->published_metadata[1] == GRPC_METADATA_NOT_PUBLISHED || s->recv_trailing_metadata_finished != nullptr) { char status_string[GPR_LTOA_MIN_BUFSIZE]; @@ -2204,7 +2200,7 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error) { if (s->read_closed && s->write_closed) { - /* already closed */ + // already closed grpc_chttp2_maybe_complete_recv_trailing_metadata(t, s); GRPC_ERROR_UNREF(error); return; @@ -2228,7 +2224,7 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, if (s->id != 0) { remove_stream(t, s->id, GRPC_ERROR_REF(overall_error)); } else { - /* Purge streams waiting on concurrency still waiting for id assignment */ + // Purge streams waiting on concurrency still waiting for id assignment grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } if (overall_error != GRPC_ERROR_NONE) { @@ -2267,12 +2263,12 @@ static void close_from_api(grpc_chttp2_transport* t, grpc_chttp2_stream* s, GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); - /* Hand roll a header block. - This is unnecessarily ugly - at some point we should find a more - elegant solution. - It's complicated by the fact that our send machinery would be dead by - the time we got around to sending this, so instead we ignore HPACK - compression and just write the uncompressed bytes onto the wire. */ + // Hand roll a header block. + // This is unnecessarily ugly - at some point we should find a more + // elegant solution. + // It's complicated by the fact that our send machinery would be dead by + // the time we got around to sending this, so instead we ignore HPACK + // compression and just write the uncompressed bytes onto the wire. if (!s->sent_initial_metadata) { http_status_hdr = GRPC_SLICE_MALLOC(13); p = GRPC_SLICE_START_PTR(http_status_hdr); @@ -2433,9 +2429,9 @@ static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error) { GRPC_ERROR_UNREF(error); } -/******************************************************************************* - * INPUT PROCESSING - PARSING - */ +// +// INPUT PROCESSING - PARSING +// template static void WithUrgency(grpc_chttp2_transport* t, @@ -2570,8 +2566,8 @@ static void read_action_locked(void* tp, grpc_error* error) { "Transport closed", &t->closed_with_error, 1); } if (error != GRPC_ERROR_NONE) { - /* If a goaway frame was received, this might be the reason why the read - * failed. Add this info to the error */ + // If a goaway frame was received, this might be the reason why the read + // failed. Add this info to the error if (t->goaway_error != GRPC_ERROR_NONE) { error = grpc_error_add_child(error, GRPC_ERROR_REF(t->goaway_error)); } @@ -2580,7 +2576,7 @@ static void read_action_locked(void* tp, grpc_error* error) { t->endpoint_reading = 0; } else if (t->closed_with_error == GRPC_ERROR_NONE) { keep_reading = true; - /* Since we have read a byte, reset the keepalive timer */ + // Since we have read a byte, reset the keepalive timer if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) { grpc_timer_cancel(&t->keepalive_ping_timer); } @@ -2641,7 +2637,7 @@ static void start_bdp_ping_locked(void* tp, grpc_error* error) { if (error != GRPC_ERROR_NONE || t->closed_with_error != GRPC_ERROR_NONE) { return; } - /* Reset the keepalive ping timer */ + // Reset the keepalive ping timer if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) { grpc_timer_cancel(&t->keepalive_ping_timer); } @@ -2667,8 +2663,8 @@ static void finish_bdp_ping_locked(void* tp, grpc_error* error) { return; } if (!t->bdp_ping_started) { - /* start_bdp_ping_locked has not been run yet. Schedule - * finish_bdp_ping_locked to be run later. */ + // start_bdp_ping_locked has not been run yet. Schedule + // finish_bdp_ping_locked to be run later. t->combiner->Run(GRPC_CLOSURE_INIT(&t->finish_bdp_ping_locked, finish_bdp_ping_locked, t, nullptr), GRPC_ERROR_REF(error)); @@ -2801,7 +2797,7 @@ static void init_keepalive_ping_locked(void* arg, grpc_error* error) { &t->init_keepalive_ping_locked); } } else if (error == GRPC_ERROR_CANCELLED) { - /* The keepalive ping timer may be cancelled by bdp */ + // The keepalive ping timer may be cancelled by bdp GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping"); GRPC_CLOSURE_INIT(&t->init_keepalive_ping_locked, init_keepalive_ping, t, grpc_schedule_on_exec_ctx); @@ -2856,8 +2852,8 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) { gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string); } if (!t->keepalive_ping_started) { - /* start_keepalive_ping_locked has not run yet. Reschedule - * finish_keepalive_ping_locked for it to be run later. */ + // start_keepalive_ping_locked has not run yet. Reschedule + // finish_keepalive_ping_locked for it to be run later. t->combiner->Run( GRPC_CLOSURE_INIT(&t->finish_keepalive_ping_locked, finish_keepalive_ping_locked, t, nullptr), @@ -2900,8 +2896,8 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { GRPC_STATUS_UNAVAILABLE)); } } else { - /* The watchdog timer should have been cancelled by - * finish_keepalive_ping_locked. */ + // The watchdog timer should have been cancelled by + // finish_keepalive_ping_locked. if (GPR_UNLIKELY(error != GRPC_ERROR_CANCELLED)) { gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)", t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING); @@ -2910,9 +2906,9 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) { GRPC_CHTTP2_UNREF_TRANSPORT(t, "keepalive watchdog"); } -/******************************************************************************* - * CALLBACK LOOP - */ +// +// CALLBACK LOOP +// static void connectivity_state_set(grpc_chttp2_transport* t, grpc_connectivity_state state, @@ -2922,9 +2918,9 @@ static void connectivity_state_set(grpc_chttp2_transport* t, t->state_tracker.SetState(state, reason); } -/******************************************************************************* - * POLLSET STUFF - */ +// +// POLLSET STUFF +// static void set_pollset(grpc_transport* gt, grpc_stream* /*gs*/, grpc_pollset* pollset) { @@ -2938,9 +2934,9 @@ static void set_pollset_set(grpc_transport* gt, grpc_stream* /*gs*/, grpc_endpoint_add_to_pollset_set(t->ep, pollset_set); } -/******************************************************************************* - * BYTE STREAM - */ +// +// BYTE STREAM +// static void reset_byte_stream(void* arg, grpc_error* error) { grpc_chttp2_stream* s = static_cast(arg); @@ -3028,7 +3024,7 @@ void Chttp2IncomingByteStream::NextLocked(void* arg, s->data_parser.parsing_frame = nullptr; } } else { - /* Should never reach here. */ + // Should never reach here. GPR_ASSERT(false); } } else { @@ -3157,9 +3153,9 @@ void Chttp2IncomingByteStream::Shutdown(grpc_error* error) { } // namespace grpc_core -/******************************************************************************* - * RESOURCE QUOTAS - */ +// +// RESOURCE QUOTAS +// static void post_benign_reclaimer(grpc_chttp2_transport* t) { if (!t->benign_reclaimer_registered) { @@ -3194,8 +3190,8 @@ static void benign_reclaimer_locked(void* arg, grpc_error* error) { grpc_chttp2_transport* t = static_cast(arg); if (error == GRPC_ERROR_NONE && grpc_chttp2_stream_map_size(&t->stream_map) == 0) { - /* Channel with no active streams: send a goaway to try and make it - * disconnect cleanly */ + // Channel with no active streams: send a goaway to try and make it + // disconnect cleanly if (GRPC_TRACE_FLAG_ENABLED(grpc_resource_quota_trace)) { gpr_log(GPR_INFO, "HTTP2: %s - send goaway to free memory", t->peer_string); @@ -3243,10 +3239,10 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM)); if (n > 1) { - /* Since we cancel one stream per destructive reclamation, if - there are more streams left, we can immediately post a new - reclaimer in case the resource quota needs to free more - memory */ + // Since we cancel one stream per destructive reclamation, if + // there are more streams left, we can immediately post a new + // reclaimer in case the resource quota needs to free more + // memory post_destructive_reclaimer(t); } } @@ -3257,9 +3253,9 @@ static void destructive_reclaimer_locked(void* arg, grpc_error* error) { GRPC_CHTTP2_UNREF_TRANSPORT(t, "destructive_reclaimer"); } -/******************************************************************************* - * MONITORING - */ +// +// MONITORING +// const char* grpc_chttp2_initiate_write_reason_string( grpc_chttp2_initiate_write_reason reason) { From 1929406660b1f5bc4c643f7072aa820bf69f56bf Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Wed, 22 Jul 2020 13:37:07 -0700 Subject: [PATCH 17/45] Clang format --- src/core/ext/transport/chttp2/transport/chttp2_transport.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc index 2f72fd451c2..8b7c7fe3db5 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.cc @@ -2200,7 +2200,7 @@ void grpc_chttp2_mark_stream_closed(grpc_chttp2_transport* t, grpc_chttp2_stream* s, int close_reads, int close_writes, grpc_error* error) { if (s->read_closed && s->write_closed) { - // already closed, but we should still fake the status if needed. + // already closed, but we should still fake the status if needed. grpc_error* overall_error = removal_error(error, s, "Stream removed"); if (overall_error != GRPC_ERROR_NONE) { grpc_chttp2_fake_status(t, s, overall_error); From ddd25a7ddb49d2ba2f8cb2afdccba6e48e3cc6ec Mon Sep 17 00:00:00 2001 From: emkornfield Date: Thu, 23 Jul 2020 13:11:46 -0700 Subject: [PATCH 18/45] Update gen_build_yaml.py remove space. --- src/boringssl/gen_build_yaml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boringssl/gen_build_yaml.py b/src/boringssl/gen_build_yaml.py index 7635f3b7970..eb4a59ae8b7 100755 --- a/src/boringssl/gen_build_yaml.py +++ b/src/boringssl/gen_build_yaml.py @@ -30,7 +30,7 @@ def map_dir(filename): class Grpc(object): - """ Adapter for boring-SSL json sources files. """ + """Adapter for boring-SSL json sources files. """ def __init__(self, sources): self.yaml = None From e0252b136254ba844291d06994bcae3fb6ff251d Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Thu, 23 Jul 2020 15:45:32 -0700 Subject: [PATCH 19/45] Make fixes to cronet_credentials.h --- include/grpcpp/security/cronet_credentials.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/grpcpp/security/cronet_credentials.h b/include/grpcpp/security/cronet_credentials.h index 008570b8cdf..81d3200e705 100644 --- a/include/grpcpp/security/cronet_credentials.h +++ b/include/grpcpp/security/cronet_credentials.h @@ -23,10 +23,7 @@ namespace grpc { -static inline std::shared_ptr -CronetChannelCredentials(void* engine) { - return ::grpc_impl::CronetChannelCredentials(engine); -} +std::shared_ptr CronetChannelCredentials(void* engine); } // namespace grpc From d2dd5900bf0bb3f5ef36be0627c804f2ac195d2c Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Thu, 23 Jul 2020 16:09:17 -0700 Subject: [PATCH 20/45] Fixing Ruby 1.31.0.pre1 compilation failure with source-only package missing re2 from build_handwritten.yaml and generated grpc.gemspec --- build_handwritten.yaml | 1 + grpc.gemspec | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/build_handwritten.yaml b/build_handwritten.yaml index f8780ff67f2..26e1af33600 100644 --- a/build_handwritten.yaml +++ b/build_handwritten.yaml @@ -264,4 +264,5 @@ ruby_gem: - address_sorting - ares - boringssl + - re2 - z diff --git a/grpc.gemspec b/grpc.gemspec index 94fe9f3959a..430651f443c 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1690,6 +1690,55 @@ Gem::Specification.new do |s| s.files += %w( third_party/cares/config_freebsd/ares_config.h ) s.files += %w( third_party/cares/config_linux/ares_config.h ) s.files += %w( third_party/cares/config_openbsd/ares_config.h ) + s.files += %w( third_party/re2/re2/bitmap256.h ) + s.files += %w( third_party/re2/re2/bitstate.cc ) + s.files += %w( third_party/re2/re2/compile.cc ) + s.files += %w( third_party/re2/re2/dfa.cc ) + s.files += %w( third_party/re2/re2/filtered_re2.cc ) + s.files += %w( third_party/re2/re2/filtered_re2.h ) + s.files += %w( third_party/re2/re2/mimics_pcre.cc ) + s.files += %w( third_party/re2/re2/nfa.cc ) + s.files += %w( third_party/re2/re2/onepass.cc ) + s.files += %w( third_party/re2/re2/parse.cc ) + s.files += %w( third_party/re2/re2/perl_groups.cc ) + s.files += %w( third_party/re2/re2/pod_array.h ) + s.files += %w( third_party/re2/re2/prefilter.cc ) + s.files += %w( third_party/re2/re2/prefilter.h ) + s.files += %w( third_party/re2/re2/prefilter_tree.cc ) + s.files += %w( third_party/re2/re2/prefilter_tree.h ) + s.files += %w( third_party/re2/re2/prog.cc ) + s.files += %w( third_party/re2/re2/prog.h ) + s.files += %w( third_party/re2/re2/re2.cc ) + s.files += %w( third_party/re2/re2/re2.h ) + s.files += %w( third_party/re2/re2/regexp.cc ) + s.files += %w( third_party/re2/re2/regexp.h ) + s.files += %w( third_party/re2/re2/set.cc ) + s.files += %w( third_party/re2/re2/set.h ) + s.files += %w( third_party/re2/re2/simplify.cc ) + s.files += %w( third_party/re2/re2/sparse_array.h ) + s.files += %w( third_party/re2/re2/sparse_set.h ) + s.files += %w( third_party/re2/re2/stringpiece.cc ) + s.files += %w( third_party/re2/re2/stringpiece.h ) + s.files += %w( third_party/re2/re2/tostring.cc ) + s.files += %w( third_party/re2/re2/unicode_casefold.cc ) + s.files += %w( third_party/re2/re2/unicode_casefold.h ) + s.files += %w( third_party/re2/re2/unicode_groups.cc ) + s.files += %w( third_party/re2/re2/unicode_groups.h ) + s.files += %w( third_party/re2/re2/walker-inl.h ) + s.files += %w( third_party/re2/util/benchmark.h ) + s.files += %w( third_party/re2/util/flags.h ) + s.files += %w( third_party/re2/util/logging.h ) + s.files += %w( third_party/re2/util/malloc_counter.h ) + s.files += %w( third_party/re2/util/mix.h ) + s.files += %w( third_party/re2/util/mutex.h ) + s.files += %w( third_party/re2/util/pcre.cc ) + s.files += %w( third_party/re2/util/pcre.h ) + s.files += %w( third_party/re2/util/rune.cc ) + s.files += %w( third_party/re2/util/strutil.cc ) + s.files += %w( third_party/re2/util/strutil.h ) + s.files += %w( third_party/re2/util/test.h ) + s.files += %w( third_party/re2/util/utf.h ) + s.files += %w( third_party/re2/util/util.h ) s.files += %w( third_party/upb/upb/decode.c ) s.files += %w( third_party/upb/upb/decode.h ) s.files += %w( third_party/upb/upb/encode.c ) From 86f6b1c046823df6db3b3c1045ba600ff75b2881 Mon Sep 17 00:00:00 2001 From: Matthew Stevenson Date: Fri, 24 Jul 2020 10:53:44 -0700 Subject: [PATCH 21/45] Disable TLS 1.3 in the C-core. --- src/core/tsi/ssl_transport_security.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/core/tsi/ssl_transport_security.cc b/src/core/tsi/ssl_transport_security.cc index 83cc98f381e..2ba932cd954 100644 --- a/src/core/tsi/ssl_transport_security.cc +++ b/src/core/tsi/ssl_transport_security.cc @@ -1894,8 +1894,11 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options( #else ssl_context = SSL_CTX_new(TLSv1_2_method()); #endif + // TODO(mattstev): Re-enable TLS 1.3 by using |options.min_tls_version| and + // |options.max_tls_version|, rather than hardcoding in TLS 1.2 as the min and + // max. result = tsi_set_min_and_max_tls_versions( - ssl_context, options->min_tls_version, options->max_tls_version); + ssl_context, tsi_tls_version::TSI_TLS1_2, tsi_tls_version::TSI_TLS1_2); if (result != TSI_OK) return result; if (ssl_context == nullptr) { gpr_log(GPR_ERROR, "Could not create ssl context."); @@ -2061,9 +2064,12 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options( #else impl->ssl_contexts[i] = SSL_CTX_new(TLSv1_2_method()); #endif + // TODO(mattstev): Re-enable TLS 1.3 by using |options.min_tls_version| + // and |options.max_tls_version|, rather than hardcoding in TLS 1.2 as the + // min and max. result = tsi_set_min_and_max_tls_versions(impl->ssl_contexts[i], - options->min_tls_version, - options->max_tls_version); + tsi_tls_version::TSI_TLS1_2, + tsi_tls_version::TSI_TLS1_2); if (result != TSI_OK) return result; if (impl->ssl_contexts[i] == nullptr) { gpr_log(GPR_ERROR, "Could not create ssl context."); From f1bc43edf6eae133c516a7eebf856537e3723954 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Fri, 24 Jul 2020 11:08:54 -0700 Subject: [PATCH 22/45] Revert "Move create_channel and credentials from ::grpc_impl to ::grpc" --- BUILD | 2 + BUILD.gn | 2 + CMakeLists.txt | 4 + Makefile | 4 + build_autogenerated.yaml | 4 + gRPC-C++.podspec | 2 + include/grpcpp/create_channel.h | 67 ++-- include/grpcpp/create_channel_impl.h | 78 ++++ .../grpcpp/impl/codegen/client_context_impl.h | 13 +- include/grpcpp/security/credentials.h | 356 +++++------------- include/grpcpp/security/credentials_impl.h | 356 ++++++++++++++++++ include/grpcpp/security/cronet_credentials.h | 5 +- include/grpcpp/security/server_credentials.h | 28 +- .../grpcpp/security/server_credentials_impl.h | 2 +- .../grpcpp/security/tls_credentials_options.h | 4 +- .../grpcpp/support/channel_arguments_impl.h | 5 +- src/cpp/client/client_context.cc | 2 +- src/cpp/client/create_channel.cc | 14 +- src/cpp/client/credentials_cc.cc | 4 +- src/cpp/client/cronet_credentials.cc | 5 +- src/cpp/client/insecure_credentials.cc | 4 +- src/cpp/client/secure_credentials.cc | 5 +- src/cpp/client/secure_credentials.h | 8 +- src/cpp/common/tls_credentials_options.cc | 4 +- .../common/tls_credentials_options_util.cc | 4 +- src/cpp/common/tls_credentials_options_util.h | 4 +- src/cpp/server/insecure_server_credentials.cc | 4 +- src/cpp/server/secure_server_credentials.cc | 6 +- src/cpp/server/secure_server_credentials.h | 13 +- test/core/security/fetch_oauth2.cc | 11 +- test/cpp/client/credentials_test.cc | 29 +- tools/doxygen/Doxyfile.c++ | 2 + tools/doxygen/Doxyfile.c++.internal | 2 + 33 files changed, 671 insertions(+), 382 deletions(-) create mode 100644 include/grpcpp/create_channel_impl.h create mode 100644 include/grpcpp/security/credentials_impl.h diff --git a/BUILD b/BUILD index 0182416c493..036c782ac30 100644 --- a/BUILD +++ b/BUILD @@ -225,6 +225,7 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", + "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", @@ -250,6 +251,7 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/credentials.h", + "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/BUILD.gn b/BUILD.gn index b81612cd95a..59835609c50 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1093,6 +1093,7 @@ config("grpc_config") { "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", + "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", @@ -1176,6 +1177,7 @@ config("grpc_config") { "include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/credentials.h", + "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 89f151b79a6..1b85e61f25a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2735,6 +2735,7 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h + include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h @@ -2818,6 +2819,7 @@ foreach(_hdr include/grpcpp/security/auth_context.h include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/credentials.h + include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h @@ -3427,6 +3429,7 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h + include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h @@ -3510,6 +3513,7 @@ foreach(_hdr include/grpcpp/security/auth_context.h include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/credentials.h + include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h diff --git a/Makefile b/Makefile index 146914f5c37..40e2642512c 100644 --- a/Makefile +++ b/Makefile @@ -4885,6 +4885,7 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ + include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -4968,6 +4969,7 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ + include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ @@ -5575,6 +5577,7 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ + include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -5658,6 +5661,7 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ + include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 5bf88a42be1..0737db79647 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2068,6 +2068,7 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h + - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h @@ -2151,6 +2152,7 @@ libs: - include/grpcpp/security/auth_context.h - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/credentials.h + - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h @@ -2452,6 +2454,7 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h + - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h @@ -2535,6 +2538,7 @@ libs: - include/grpcpp/security/auth_context.h - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/credentials.h + - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 2633038e47b..c1f21867f5e 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -84,6 +84,7 @@ Pod::Spec.new do |s| 'include/grpcpp/completion_queue.h', 'include/grpcpp/completion_queue_impl.h', 'include/grpcpp/create_channel.h', + 'include/grpcpp/create_channel_impl.h', 'include/grpcpp/create_channel_posix.h', 'include/grpcpp/ext/health_check_service_server_builder_option.h', 'include/grpcpp/generic/async_generic_service.h', @@ -163,6 +164,7 @@ Pod::Spec.new do |s| 'include/grpcpp/security/auth_context.h', 'include/grpcpp/security/auth_metadata_processor.h', 'include/grpcpp/security/credentials.h', + 'include/grpcpp/security/credentials_impl.h', 'include/grpcpp/security/server_credentials.h', 'include/grpcpp/security/server_credentials_impl.h', 'include/grpcpp/security/tls_credentials_options.h', diff --git a/include/grpcpp/create_channel.h b/include/grpcpp/create_channel.h index 4b94a08e45e..bfd018b26f0 100644 --- a/include/grpcpp/create_channel.h +++ b/include/grpcpp/create_channel.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015 gRPC authors. + * 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. @@ -19,59 +19,36 @@ #ifndef GRPCPP_CREATE_CHANNEL_H #define GRPCPP_CREATE_CHANNEL_H -#include - -#include -#include -#include +#include #include -#include namespace grpc { -/// Create a new \a Channel pointing to \a target. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -std::shared_ptr CreateChannel( - const grpc::string& target, - const std::shared_ptr& creds); -/// Create a new \em custom \a Channel pointing to \a target. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr CreateCustomChannel( - const grpc::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args); +static inline std::shared_ptr<::grpc::Channel> CreateChannel( + const std::string& target, + const std::shared_ptr& creds) { + return ::grpc_impl::CreateChannelImpl(target, creds); +} + +static inline std::shared_ptr<::grpc::Channel> CreateCustomChannel( + const std::string& target, const std::shared_ptr& creds, + const ChannelArguments& args) { + return ::grpc_impl::CreateCustomChannelImpl(target, creds, args); +} namespace experimental { -/// Create a new \em custom \a Channel pointing to \a target with \a -/// interceptors being invoked per call. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, + +static inline std::shared_ptr<::grpc::Channel> +CreateCustomChannelWithInterceptors( + const std::string& target, const std::shared_ptr& creds, const ChannelArguments& args, std::vector< std::unique_ptr> - interceptor_creators); + interceptor_creators) { + return ::grpc_impl::experimental::CreateCustomChannelWithInterceptors( + target, creds, args, std::move(interceptor_creators)); +} + } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/create_channel_impl.h b/include/grpcpp/create_channel_impl.h new file mode 100644 index 00000000000..ac68728692c --- /dev/null +++ b/include/grpcpp/create_channel_impl.h @@ -0,0 +1,78 @@ +/* + * + * Copyright 2015 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. + * + */ + +#ifndef GRPCPP_CREATE_CHANNEL_IMPL_H +#define GRPCPP_CREATE_CHANNEL_IMPL_H + +#include + +#include +#include +#include +#include +#include + +namespace grpc_impl { +/// Create a new \a Channel pointing to \a target. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +std::shared_ptr<::grpc::Channel> CreateChannelImpl( + const std::string& target, + const std::shared_ptr<::grpc::ChannelCredentials>& creds); + +/// Create a new \em custom \a Channel pointing to \a target. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr<::grpc::Channel> CreateCustomChannelImpl( + const std::string& target, + const std::shared_ptr<::grpc::ChannelCredentials>& creds, + const ::grpc::ChannelArguments& args); + +namespace experimental { +/// Create a new \em custom \a Channel pointing to \a target with \a +/// interceptors being invoked per call. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr<::grpc::Channel> CreateCustomChannelWithInterceptors( + const std::string& target, + const std::shared_ptr& creds, + const ::grpc::ChannelArguments& args, + std::vector< + std::unique_ptr> + interceptor_creators); +} // namespace experimental +} // namespace grpc_impl + +#endif // GRPCPP_CREATE_CHANNEL_IMPL_H diff --git a/include/grpcpp/impl/codegen/client_context_impl.h b/include/grpcpp/impl/codegen/client_context_impl.h index 2624e571cdb..9b6d1755edb 100644 --- a/include/grpcpp/impl/codegen/client_context_impl.h +++ b/include/grpcpp/impl/codegen/client_context_impl.h @@ -58,7 +58,6 @@ struct grpc_call; namespace grpc { -class CallCredentials; class ChannelInterface; namespace internal { @@ -89,6 +88,7 @@ class ClientCallbackUnaryImpl; class ClientContextAccessor; } // namespace internal +class CallCredentials; class Channel; class CompletionQueue; class ServerContext; @@ -318,15 +318,16 @@ class ClientContext { /// /// It is legal to call this only before initial metadata is sent. /// - /// \see https://grpc.io/docs/guides/auth.html - void set_credentials(const std::shared_ptr& creds); + /// \see https://grpc.io/docs/guides/auth + void set_credentials( + const std::shared_ptr& creds); /// EXPERIMENTAL debugging API /// /// Returns the credentials for the client call. This should be used only in /// tests and for diagnostic purposes, and should not be used by application /// logic. - std::shared_ptr credentials() { return creds_; } + std::shared_ptr credentials() { return creds_; } /// Return the compression algorithm the client call will request be used. /// Note that the gRPC runtime may decide to ignore this request, for example, @@ -493,8 +494,8 @@ class ClientContext { grpc_call* call_; bool call_canceled_; gpr_timespec deadline_; - grpc::string authority_; - std::shared_ptr creds_; + std::string authority_; + std::shared_ptr creds_; mutable std::shared_ptr auth_context_; struct census_context* census_context_; std::multimap send_initial_metadata_; diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index b0da6650b6b..45c6d55546f 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -19,301 +19,123 @@ #ifndef GRPCPP_SECURITY_CREDENTIALS_H #define GRPCPP_SECURITY_CREDENTIALS_H -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct grpc_call; +#include namespace grpc { -class CallCredentials; -class SecureCallCredentials; -class SecureChannelCredentials; -class ChannelCredentials; -std::shared_ptr CreateCustomChannel( - const grpc::string& target, - const std::shared_ptr& creds, - const grpc::ChannelArguments& args); +typedef ::grpc_impl::ChannelCredentials ChannelCredentials; +typedef ::grpc_impl::CallCredentials CallCredentials; +typedef ::grpc_impl::SslCredentialsOptions SslCredentialsOptions; +typedef ::grpc_impl::SecureCallCredentials SecureCallCredentials; +typedef ::grpc_impl::SecureChannelCredentials SecureChannelCredentials; +typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; -namespace experimental { -std::shared_ptr CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, - const grpc::ChannelArguments& args, - std::vector< - std::unique_ptr> - interceptor_creators); +static inline std::shared_ptr +GoogleDefaultCredentials() { + return ::grpc_impl::GoogleDefaultCredentials(); } -/// A channel credentials object encapsulates all the state needed by a client -/// to authenticate with a server for a given channel. -/// It can make various assertions, e.g., about the client’s identity, role -/// for all the calls on that channel. -/// -/// \see https://grpc.io/docs/guides/auth.html -class ChannelCredentials : private grpc::GrpcLibraryCodegen { - public: - ChannelCredentials(); - ~ChannelCredentials(); - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - virtual SecureChannelCredentials* AsSecureCredentials() = 0; - - private: - friend std::shared_ptr CreateCustomChannel( - const grpc::string& target, - const std::shared_ptr& creds, - const grpc::ChannelArguments& args); - - friend std::shared_ptr - grpc::experimental::CreateCustomChannelWithInterceptors( - const grpc::string& target, - const std::shared_ptr& creds, - const grpc::ChannelArguments& args, - std::vector> - interceptor_creators); - - virtual std::shared_ptr CreateChannelImpl( - const grpc::string& target, const ChannelArguments& args) = 0; - - // This function should have been a pure virtual function, but it is - // implemented as a virtual function so that it does not break API. - virtual std::shared_ptr CreateChannelWithInterceptors( - const grpc::string& /*target*/, const ChannelArguments& /*args*/, - std::vector> - /*interceptor_creators*/) { - return nullptr; - } -}; - -/// A call credentials object encapsulates the state needed by a client to -/// authenticate with a server for a given call on a channel. -/// -/// \see https://grpc.io/docs/guides/auth.html -class CallCredentials : private grpc::GrpcLibraryCodegen { - public: - CallCredentials(); - ~CallCredentials(); - - /// Apply this instance's credentials to \a call. - virtual bool ApplyToCall(grpc_call* call) = 0; - virtual grpc::string DebugString() { - return "CallCredentials did not provide a debug string"; - } - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - friend std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - - virtual SecureCallCredentials* AsSecureCredentials() = 0; -}; - -/// Options used to build SslCredentials. -struct SslCredentialsOptions { - /// The buffer containing the PEM encoding of the server root certificates. If - /// this parameter is empty, the default roots will be used. The default - /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH - /// environment variable pointing to a file on the file system containing the - /// roots. - grpc::string pem_root_certs; - - /// The buffer containing the PEM encoding of the client's private key. This - /// parameter can be empty if the client does not have a private key. - grpc::string pem_private_key; - - /// The buffer containing the PEM encoding of the client's certificate chain. - /// This parameter can be empty if the client does not have a certificate - /// chain. - grpc::string pem_cert_chain; -}; - -// Factories for building different types of Credentials The functions may -// return empty shared_ptr when credentials cannot be created. If a -// Credentials pointer is returned, it can still be invalid when used to create -// a channel. A lame channel will be created then and all rpcs will fail on it. - -/// Builds credentials with reasonable defaults. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleDefaultCredentials(); - -/// Builds SSL Credentials given SSL specific options -std::shared_ptr SslCredentials( - const SslCredentialsOptions& options); +static inline std::shared_ptr SslCredentials( + const SslCredentialsOptions& options) { + return ::grpc_impl::SslCredentials(options); +} -/// Builds credentials for use when running in GCE -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleComputeEngineCredentials(); +static inline std::shared_ptr +GoogleComputeEngineCredentials() { + return ::grpc_impl::GoogleComputeEngineCredentials(); +} -constexpr long kMaxAuthTokenLifetimeSecs = 3600; +/// Constant for maximum auth token lifetime. +constexpr long kMaxAuthTokenLifetimeSecs = + ::grpc_impl::kMaxAuthTokenLifetimeSecs; -/// Builds Service Account JWT Access credentials. -/// json_key is the JSON key string containing the client's private key. -/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token -/// (JWT) created with this credentials. It should not exceed -/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. -std::shared_ptr ServiceAccountJWTAccessCredentials( - const grpc::string& json_key, - long token_lifetime_seconds = kMaxAuthTokenLifetimeSecs); +static inline std::shared_ptr +ServiceAccountJWTAccessCredentials( + const std::string& json_key, + long token_lifetime_seconds = grpc::kMaxAuthTokenLifetimeSecs) { + return ::grpc_impl::ServiceAccountJWTAccessCredentials( + json_key, token_lifetime_seconds); +} -/// Builds refresh token credentials. -/// json_refresh_token is the JSON string containing the refresh token along -/// with a client_id and client_secret. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleRefreshTokenCredentials( - const grpc::string& json_refresh_token); +static inline std::shared_ptr +GoogleRefreshTokenCredentials(const std::string& json_refresh_token) { + return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token); +} -/// Builds access token credentials. -/// access_token is an oauth2 access token that was fetched using an out of band -/// mechanism. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr AccessTokenCredentials( - const grpc::string& access_token); +static inline std::shared_ptr +AccessTokenCredentials(const std::string& access_token) { + return ::grpc_impl::AccessTokenCredentials(access_token); +} -/// Builds IAM credentials. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleIAMCredentials( - const grpc::string& authorization_token, - const grpc::string& authority_selector); +static inline std::shared_ptr GoogleIAMCredentials( + const std::string& authorization_token, + const std::string& authority_selector) { + return ::grpc_impl::GoogleIAMCredentials(authorization_token, + authority_selector); +} -/// Combines a channel credentials and a call credentials into a composite -/// channel credentials. -std::shared_ptr CompositeChannelCredentials( +static inline std::shared_ptr CompositeChannelCredentials( const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - -/// Combines two call credentials objects into a composite call credentials. -std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - -/// Credentials for an unencrypted, unauthenticated channel -std::shared_ptr InsecureChannelCredentials(); - -/// User defined metadata credentials. -class MetadataCredentialsPlugin { - public: - virtual ~MetadataCredentialsPlugin() {} - - /// If this method returns true, the Process function will be scheduled in - /// a different thread from the one processing the call. - virtual bool IsBlocking() const { return true; } + const std::shared_ptr& call_creds) { + return ::grpc_impl::CompositeChannelCredentials(channel_creds, call_creds); +} - /// Type of credentials this plugin is implementing. - virtual const char* GetType() const { return ""; } +static inline std::shared_ptr +CompositeCallCredentials(const std::shared_ptr& creds1, + const std::shared_ptr& creds2) { + return ::grpc_impl::CompositeCallCredentials(creds1, creds2); +} - /// Gets the auth metatada produced by this plugin. - /// The fully qualified method name is: - /// service_url + "/" + method_name. - /// The channel_auth_context contains (among other things), the identity of - /// the server. - virtual grpc::Status GetMetadata( - grpc::string_ref service_url, grpc::string_ref method_name, - const grpc::AuthContext& channel_auth_context, - std::multimap* metadata) = 0; +static inline std::shared_ptr +InsecureChannelCredentials() { + return ::grpc_impl::InsecureChannelCredentials(); +} - virtual grpc::string DebugString() { - return "MetadataCredentialsPlugin did not provide a debug string"; - } -}; +typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin); +static inline std::shared_ptr +MetadataCredentialsFromPlugin( + std::unique_ptr plugin) { + return ::grpc_impl::MetadataCredentialsFromPlugin(std::move(plugin)); +} namespace experimental { -/// Options for creating STS Oauth Token Exchange credentials following the IETF -/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. -/// Optional fields may be set to empty string. It is the responsibility of the -/// caller to ensure that the subject and actor tokens are refreshed on disk at -/// the specified paths. -struct StsCredentialsOptions { - grpc::string token_exchange_service_uri; // Required. - grpc::string resource; // Optional. - grpc::string audience; // Optional. - grpc::string scope; // Optional. - grpc::string requested_token_type; // Optional. - grpc::string subject_token_path; // Required. - grpc::string subject_token_type; // Required. - grpc::string actor_token_path; // Optional. - grpc::string actor_token_type; // Optional. -}; +typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions; -grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, - StsCredentialsOptions* options); - -/// Creates STS credentials options from the $STS_CREDENTIALS environment -/// variable. This environment variable points to the path of a JSON file -/// comforming to the schema described above. -grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); +static inline grpc::Status StsCredentialsOptionsFromJson( + const std::string& json_string, StsCredentialsOptions* options) { + return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string, + options); +} -std::shared_ptr StsCredentials( - const StsCredentialsOptions& options); +static inline grpc::Status StsCredentialsOptionsFromEnv( + StsCredentialsOptions* options) { + return grpc_impl::experimental::StsCredentialsOptionsFromEnv(options); +} -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin, - grpc_security_level min_security_level); +static inline std::shared_ptr StsCredentials( + const StsCredentialsOptions& options) { + return grpc_impl::experimental::StsCredentials(options); +} -/// Options used to build AltsCredentials. -struct AltsCredentialsOptions { - /// service accounts of target endpoint that will be acceptable - /// by the client. If service accounts are provided and none of them matches - /// that of the server, authentication will fail. - std::vector target_service_accounts; -}; +typedef ::grpc_impl::experimental::AltsCredentialsOptions + AltsCredentialsOptions; -/// Builds ALTS Credentials given ALTS specific options -std::shared_ptr AltsCredentials( - const AltsCredentialsOptions& options); +static inline std::shared_ptr AltsCredentials( + const AltsCredentialsOptions& options) { + return ::grpc_impl::experimental::AltsCredentials(options); +} -/// Builds Local Credentials. -std::shared_ptr LocalCredentials( - grpc_local_connect_type type); +static inline std::shared_ptr LocalCredentials( + grpc_local_connect_type type) { + return ::grpc_impl::experimental::LocalCredentials(type); +} -/// Builds TLS Credentials given TLS options. -std::shared_ptr TlsCredentials( - const TlsCredentialsOptions& options); +static inline std::shared_ptr TlsCredentials( + const ::grpc_impl::experimental::TlsCredentialsOptions& options) { + return ::grpc_impl::experimental::TlsCredentials(options); +} } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/credentials_impl.h b/include/grpcpp/security/credentials_impl.h new file mode 100644 index 00000000000..84206a688bc --- /dev/null +++ b/include/grpcpp/security/credentials_impl.h @@ -0,0 +1,356 @@ +/* + * + * Copyright 2015 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. + * + */ + +#ifndef GRPCPP_SECURITY_CREDENTIALS_IMPL_H +#define GRPCPP_SECURITY_CREDENTIALS_IMPL_H + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct grpc_call; + +namespace grpc_impl { + +class ChannelCredentials; +class CallCredentials; +class SecureCallCredentials; +class SecureChannelCredentials; + +std::shared_ptr CreateCustomChannelImpl( + const std::string& target, const std::shared_ptr& creds, + const ChannelArguments& args); + +namespace experimental { +std::shared_ptr CreateCustomChannelWithInterceptors( + const std::string& target, const std::shared_ptr& creds, + const ChannelArguments& args, + std::vector< + std::unique_ptr> + interceptor_creators); +} + +/// A channel credentials object encapsulates all the state needed by a client +/// to authenticate with a server for a given channel. +/// It can make various assertions, e.g., about the client’s identity, role +/// for all the calls on that channel. +/// +/// \see https://grpc.io/docs/guides/auth +class ChannelCredentials : private grpc::GrpcLibraryCodegen { + public: + ChannelCredentials(); + ~ChannelCredentials(); + + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + + virtual SecureChannelCredentials* AsSecureCredentials() = 0; + + private: + friend std::shared_ptr CreateCustomChannelImpl( + const std::string& target, + const std::shared_ptr& creds, + const ChannelArguments& args); + + friend std::shared_ptr + grpc_impl::experimental::CreateCustomChannelWithInterceptors( + const std::string& target, + const std::shared_ptr& creds, + const ChannelArguments& args, + std::vector> + interceptor_creators); + + virtual std::shared_ptr CreateChannelImpl( + const std::string& target, const ChannelArguments& args) = 0; + + // This function should have been a pure virtual function, but it is + // implemented as a virtual function so that it does not break API. + virtual std::shared_ptr CreateChannelWithInterceptors( + const std::string& /*target*/, const ChannelArguments& /*args*/, + std::vector> + /*interceptor_creators*/) { + return nullptr; + } +}; + +/// A call credentials object encapsulates the state needed by a client to +/// authenticate with a server for a given call on a channel. +/// +/// \see https://grpc.io/docs/guides/auth +class CallCredentials : private grpc::GrpcLibraryCodegen { + public: + CallCredentials(); + ~CallCredentials(); + + /// Apply this instance's credentials to \a call. + virtual bool ApplyToCall(grpc_call* call) = 0; + virtual std::string DebugString() { + return "CallCredentials did not provide a debug string"; + } + + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + + friend std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); + + virtual SecureCallCredentials* AsSecureCredentials() = 0; +}; + +/// Options used to build SslCredentials. +struct SslCredentialsOptions { + /// The buffer containing the PEM encoding of the server root certificates. If + /// this parameter is empty, the default roots will be used. The default + /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH + /// environment variable pointing to a file on the file system containing the + /// roots. + std::string pem_root_certs; + + /// The buffer containing the PEM encoding of the client's private key. This + /// parameter can be empty if the client does not have a private key. + std::string pem_private_key; + + /// The buffer containing the PEM encoding of the client's certificate chain. + /// This parameter can be empty if the client does not have a certificate + /// chain. + std::string pem_cert_chain; +}; + +// Factories for building different types of Credentials The functions may +// return empty shared_ptr when credentials cannot be created. If a +// Credentials pointer is returned, it can still be invalid when used to create +// a channel. A lame channel will be created then and all rpcs will fail on it. + +/// Builds credentials with reasonable defaults. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleDefaultCredentials(); + +/// Builds SSL Credentials given SSL specific options +std::shared_ptr SslCredentials( + const SslCredentialsOptions& options); + +/// Builds credentials for use when running in GCE +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleComputeEngineCredentials(); + +constexpr long kMaxAuthTokenLifetimeSecs = 3600; + +/// Builds Service Account JWT Access credentials. +/// json_key is the JSON key string containing the client's private key. +/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token +/// (JWT) created with this credentials. It should not exceed +/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. +std::shared_ptr ServiceAccountJWTAccessCredentials( + const std::string& json_key, + long token_lifetime_seconds = grpc_impl::kMaxAuthTokenLifetimeSecs); + +/// Builds refresh token credentials. +/// json_refresh_token is the JSON string containing the refresh token along +/// with a client_id and client_secret. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleRefreshTokenCredentials( + const std::string& json_refresh_token); + +/// Builds access token credentials. +/// access_token is an oauth2 access token that was fetched using an out of band +/// mechanism. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr AccessTokenCredentials( + const std::string& access_token); + +/// Builds IAM credentials. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleIAMCredentials( + const std::string& authorization_token, + const std::string& authority_selector); + +/// Combines a channel credentials and a call credentials into a composite +/// channel credentials. +std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + +/// Combines two call credentials objects into a composite call credentials. +std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); + +/// Credentials for an unencrypted, unauthenticated channel +std::shared_ptr InsecureChannelCredentials(); + +/// User defined metadata credentials. +class MetadataCredentialsPlugin { + public: + virtual ~MetadataCredentialsPlugin() {} + + /// If this method returns true, the Process function will be scheduled in + /// a different thread from the one processing the call. + virtual bool IsBlocking() const { return true; } + + /// Type of credentials this plugin is implementing. + virtual const char* GetType() const { return ""; } + + /// Gets the auth metatada produced by this plugin. + /// The fully qualified method name is: + /// service_url + "/" + method_name. + /// The channel_auth_context contains (among other things), the identity of + /// the server. + virtual grpc::Status GetMetadata( + grpc::string_ref service_url, grpc::string_ref method_name, + const grpc::AuthContext& channel_auth_context, + std::multimap* metadata) = 0; + + virtual std::string DebugString() { + return "MetadataCredentialsPlugin did not provide a debug string"; + } +}; + +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin); + +namespace experimental { + +/// Options for creating STS Oauth Token Exchange credentials following the IETF +/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. +/// Optional fields may be set to empty string. It is the responsibility of the +/// caller to ensure that the subject and actor tokens are refreshed on disk at +/// the specified paths. +struct StsCredentialsOptions { + std::string token_exchange_service_uri; // Required. + std::string resource; // Optional. + std::string audience; // Optional. + std::string scope; // Optional. + std::string requested_token_type; // Optional. + std::string subject_token_path; // Required. + std::string subject_token_type; // Required. + std::string actor_token_path; // Optional. + std::string actor_token_type; // Optional. +}; + +/// Creates STS Options from a JSON string. The JSON schema is as follows: +/// { +/// "title": "STS Credentials Config", +/// "type": "object", +/// "required": ["token_exchange_service_uri", "subject_token_path", +/// "subject_token_type"], +/// "properties": { +/// "token_exchange_service_uri": { +/// "type": "string" +/// }, +/// "resource": { +/// "type": "string" +/// }, +/// "audience": { +/// "type": "string" +/// }, +/// "scope": { +/// "type": "string" +/// }, +/// "requested_token_type": { +/// "type": "string" +/// }, +/// "subject_token_path": { +/// "type": "string" +/// }, +/// "subject_token_type": { +/// "type": "string" +/// }, +/// "actor_token_path" : { +/// "type": "string" +/// }, +/// "actor_token_type": { +/// "type": "string" +/// } +/// } +/// } +grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, + StsCredentialsOptions* options); + +/// Creates STS credentials options from the $STS_CREDENTIALS environment +/// variable. This environment variable points to the path of a JSON file +/// comforming to the schema described above. +grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); + +std::shared_ptr StsCredentials( + const StsCredentialsOptions& options); + +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin, + grpc_security_level min_security_level); + +/// Options used to build AltsCredentials. +struct AltsCredentialsOptions { + /// service accounts of target endpoint that will be acceptable + /// by the client. If service accounts are provided and none of them matches + /// that of the server, authentication will fail. + std::vector target_service_accounts; +}; + +/// Builds ALTS Credentials given ALTS specific options +std::shared_ptr AltsCredentials( + const AltsCredentialsOptions& options); + +/// Builds Local Credentials. +std::shared_ptr LocalCredentials( + grpc_local_connect_type type); + +/// Builds TLS Credentials given TLS options. +std::shared_ptr TlsCredentials( + const TlsCredentialsOptions& options); + +} // namespace experimental +} // namespace grpc_impl + +#endif // GRPCPP_SECURITY_CREDENTIALS_IMPL_H diff --git a/include/grpcpp/security/cronet_credentials.h b/include/grpcpp/security/cronet_credentials.h index 81d3200e705..008570b8cdf 100644 --- a/include/grpcpp/security/cronet_credentials.h +++ b/include/grpcpp/security/cronet_credentials.h @@ -23,7 +23,10 @@ namespace grpc { -std::shared_ptr CronetChannelCredentials(void* engine); +static inline std::shared_ptr +CronetChannelCredentials(void* engine) { + return ::grpc_impl::CronetChannelCredentials(engine); +} } // namespace grpc diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index 1223b10978e..5228ac138cc 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -55,25 +55,35 @@ struct SslServerCredentialsOptions { grpc_ssl_client_certificate_request_type client_certificate_request; }; -std::shared_ptr SslServerCredentials( - const SslServerCredentialsOptions& options); +static inline std::shared_ptr SslServerCredentials( + const SslServerCredentialsOptions& options) { + return ::grpc_impl::SslServerCredentials(options); +} -std::shared_ptr InsecureServerCredentials(); +static inline std::shared_ptr InsecureServerCredentials() { + return ::grpc_impl::InsecureServerCredentials(); +} namespace experimental { typedef ::grpc_impl::experimental::AltsServerCredentialsOptions AltsServerCredentialsOptions; -std::shared_ptr AltsServerCredentials( - const AltsServerCredentialsOptions& options); +static inline std::shared_ptr AltsServerCredentials( + const AltsServerCredentialsOptions& options) { + return ::grpc_impl::experimental::AltsServerCredentials(options); +} -std::shared_ptr LocalServerCredentials( - grpc_local_connect_type type); +static inline std::shared_ptr LocalServerCredentials( + grpc_local_connect_type type) { + return ::grpc_impl::experimental::LocalServerCredentials(type); +} /// Builds TLS ServerCredentials given TLS options. -std::shared_ptr TlsServerCredentials( - const ::grpc::experimental::TlsCredentialsOptions& options); +static inline std::shared_ptr TlsServerCredentials( + const ::grpc_impl::experimental::TlsCredentialsOptions& options) { + return ::grpc_impl::experimental::TlsServerCredentials(options); +} } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/server_credentials_impl.h b/include/grpcpp/security/server_credentials_impl.h index 734409ab8e5..7e9e784f6e5 100644 --- a/include/grpcpp/security/server_credentials_impl.h +++ b/include/grpcpp/security/server_credentials_impl.h @@ -81,7 +81,7 @@ std::shared_ptr LocalServerCredentials( /// Builds TLS ServerCredentials given TLS options. std::shared_ptr TlsServerCredentials( - const grpc::experimental::TlsCredentialsOptions& options); + const TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc_impl diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index 9613e2f69ba..8df44e37f93 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -36,7 +36,7 @@ typedef struct grpc_tls_server_authorization_check_config grpc_tls_server_authorization_check_config; typedef struct grpc_tls_credentials_options grpc_tls_credentials_options; -namespace grpc { +namespace grpc_impl { namespace experimental { /** TLS key materials config, wrapper for grpc_tls_key_materials_config. It is @@ -340,6 +340,6 @@ class TlsCredentialsOptions { }; } // namespace experimental -} // namespace grpc +} // namespace grpc_impl #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H diff --git a/include/grpcpp/support/channel_arguments_impl.h b/include/grpcpp/support/channel_arguments_impl.h index 28cb0cef082..e526f72f177 100644 --- a/include/grpcpp/support/channel_arguments_impl.h +++ b/include/grpcpp/support/channel_arguments_impl.h @@ -28,7 +28,6 @@ #include namespace grpc { -class SecureChannelCredentials; namespace testing { class ChannelArgumentsTest; } // namespace testing @@ -36,6 +35,8 @@ class ChannelArgumentsTest; namespace grpc_impl { +class SecureChannelCredentials; + /// Options for channel creation. The user can use generic setters to pass /// key value pairs down to C channel creation code. For gRPC related options, /// concrete setters are provided. @@ -125,7 +126,7 @@ class ChannelArguments { } private: - friend class grpc::SecureChannelCredentials; + friend class grpc_impl::SecureChannelCredentials; friend class grpc::testing::ChannelArgumentsTest; /// Default pointer argument operations. diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index d0ec597fc63..8642799e905 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -73,7 +73,7 @@ ClientContext::~ClientContext() { } void ClientContext::set_credentials( - const std::shared_ptr& creds) { + const std::shared_ptr& creds) { creds_ = creds; // If call_ is set, we have already created the call, and set the call // credentials. This should only be done before we have started the batch diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index 48831d0fede..2bbeebc2df6 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -26,15 +26,15 @@ #include "src/cpp/client/create_channel_internal.h" -namespace grpc { -std::shared_ptr CreateChannel( - const grpc::string& target, +namespace grpc_impl { +std::shared_ptr CreateChannelImpl( + const std::string& target, const std::shared_ptr& creds) { - return CreateCustomChannel(target, creds, grpc::ChannelArguments()); + return CreateCustomChannelImpl(target, creds, grpc::ChannelArguments()); } -std::shared_ptr CreateCustomChannel( - const grpc::string& target, +std::shared_ptr CreateCustomChannelImpl( + const std::string& target, const std::shared_ptr& creds, const grpc::ChannelArguments& args) { grpc::GrpcLibraryCodegen @@ -82,4 +82,4 @@ std::shared_ptr CreateCustomChannelWithInterceptors( } } // namespace experimental -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/client/credentials_cc.cc b/src/cpp/client/credentials_cc.cc index 9dfb2f491ca..62334bd9eba 100644 --- a/src/cpp/client/credentials_cc.cc +++ b/src/cpp/client/credentials_cc.cc @@ -19,7 +19,7 @@ #include #include -namespace grpc { +namespace grpc_impl { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; ChannelCredentials::ChannelCredentials() { g_gli_initializer.summon(); } @@ -30,4 +30,4 @@ CallCredentials::CallCredentials() { g_gli_initializer.summon(); } CallCredentials::~CallCredentials() {} -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/client/cronet_credentials.cc b/src/cpp/client/cronet_credentials.cc index d09e2841279..f4ead14cde8 100644 --- a/src/cpp/client/cronet_credentials.cc +++ b/src/cpp/client/cronet_credentials.cc @@ -55,9 +55,10 @@ class CronetChannelCredentialsImpl final : public ChannelCredentials { } void* engine_; }; - +} // namespace grpc +namespace grpc_impl { std::shared_ptr CronetChannelCredentials(void* engine) { return std::shared_ptr( new grpc::CronetChannelCredentialsImpl(engine)); } -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc index a9be08d5a10..0495b9378b0 100644 --- a/src/cpp/client/insecure_credentials.cc +++ b/src/cpp/client/insecure_credentials.cc @@ -24,7 +24,7 @@ #include #include "src/cpp/client/create_channel_internal.h" -namespace grpc { +namespace grpc_impl { namespace { class InsecureChannelCredentialsImpl final : public ChannelCredentials { @@ -59,4 +59,4 @@ std::shared_ptr InsecureChannelCredentials() { new InsecureChannelCredentialsImpl()); } -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 378cceaa114..108762e76ab 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -38,7 +38,7 @@ #include "src/cpp/client/create_channel_internal.h" #include "src/cpp/common/secure_auth_context.h" -namespace grpc { +namespace grpc_impl { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; SecureChannelCredentials::SecureChannelCredentials( @@ -388,6 +388,9 @@ std::shared_ptr MetadataCredentialsFromPlugin( c_plugin, GRPC_PRIVACY_AND_INTEGRITY, nullptr)); } +} // namespace grpc_impl + +namespace grpc { namespace { void DeleteWrapper(void* wrapper, grpc_error* /*ignored*/) { MetadataCredentialsPluginWrapper* w = diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 7d36de2adcc..9238738146d 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -32,9 +33,6 @@ namespace grpc_impl { class Channel; -} // namespace grpc_impl - -namespace grpc { class SecureChannelCredentials final : public ChannelCredentials { public: @@ -87,6 +85,10 @@ grpc_sts_credentials_options StsCredentialsCppToCoreOptions( } // namespace experimental +} // namespace grpc_impl + +namespace grpc { + class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); diff --git a/src/cpp/common/tls_credentials_options.cc b/src/cpp/common/tls_credentials_options.cc index 011cf4b3e5d..a9122e962d3 100644 --- a/src/cpp/common/tls_credentials_options.cc +++ b/src/cpp/common/tls_credentials_options.cc @@ -23,7 +23,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc { +namespace grpc_impl { namespace experimental { /** TLS key materials config API implementation **/ @@ -340,4 +340,4 @@ TlsCredentialsOptions::TlsCredentialsOptions( TlsCredentialsOptions::~TlsCredentialsOptions() {} } // namespace experimental -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/common/tls_credentials_options_util.cc b/src/cpp/common/tls_credentials_options_util.cc index 51cc4e2aefa..2211460e664 100644 --- a/src/cpp/common/tls_credentials_options_util.cc +++ b/src/cpp/common/tls_credentials_options_util.cc @@ -21,7 +21,7 @@ #include #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc { +namespace grpc_impl { namespace experimental { /** Converts the Cpp key materials to C key materials; this allocates memory for @@ -146,4 +146,4 @@ void TlsServerAuthorizationCheckArgDestroyContext(void* context) { } } // namespace experimental -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/common/tls_credentials_options_util.h b/src/cpp/common/tls_credentials_options_util.h index 4ee04d15d7f..93e94562398 100644 --- a/src/cpp/common/tls_credentials_options_util.h +++ b/src/cpp/common/tls_credentials_options_util.h @@ -24,7 +24,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" -namespace grpc { +namespace grpc_impl { namespace experimental { /** The following function is exposed for testing purposes. **/ @@ -53,6 +53,6 @@ void TlsCredentialReloadArgDestroyContext(void* context); void TlsServerAuthorizationCheckArgDestroyContext(void* context); } // namespace experimental -} // namespace grpc +} // namespace grpc_impl #endif // GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc index 04e5435efb9..bc908920b8d 100644 --- a/src/cpp/server/insecure_server_credentials.cc +++ b/src/cpp/server/insecure_server_credentials.cc @@ -21,7 +21,7 @@ #include #include -namespace grpc { +namespace grpc_impl { namespace { class InsecureServerCredentialsImpl final : public ServerCredentials { public: @@ -41,4 +41,4 @@ std::shared_ptr InsecureServerCredentials() { new InsecureServerCredentialsImpl()); } -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 48fb3ad9f34..f94696fd767 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -94,7 +94,7 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( } // namespace grpc -namespace grpc { +namespace grpc_impl { int SecureServerCredentials::AddPortToServer(const std::string& addr, grpc_server* server) { @@ -149,11 +149,11 @@ std::shared_ptr LocalServerCredentials( } std::shared_ptr TlsServerCredentials( - const grpc::experimental::TlsCredentialsOptions& options) { + const TlsCredentialsOptions& options) { grpc::GrpcLibraryCodegen init; return std::shared_ptr(new SecureServerCredentials( grpc_tls_server_credentials_create(options.c_credentials_options()))); } } // namespace experimental -} // namespace grpc +} // namespace grpc_impl diff --git a/src/cpp/server/secure_server_credentials.h b/src/cpp/server/secure_server_credentials.h index 407d70766b5..9e9e33579f0 100644 --- a/src/cpp/server/secure_server_credentials.h +++ b/src/cpp/server/secure_server_credentials.h @@ -28,9 +28,14 @@ #include "src/cpp/server/thread_pool_interface.h" -namespace grpc { +namespace grpc_impl { class SecureServerCredentials; +} // namespace grpc_impl + +namespace grpc { + +typedef ::grpc_impl::SecureServerCredentials SecureServerCredentials; class AuthMetadataProcessorAyncWrapper final { public: @@ -56,6 +61,10 @@ class AuthMetadataProcessorAyncWrapper final { std::shared_ptr processor_; }; +} // namespace grpc + +namespace grpc_impl { + class SecureServerCredentials final : public ServerCredentials { public: explicit SecureServerCredentials(grpc_server_credentials* creds) @@ -74,6 +83,6 @@ class SecureServerCredentials final : public ServerCredentials { std::unique_ptr processor_; }; -} // namespace grpc +} // namespace grpc_impl #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 99d7c76d0d3..1aa999758b0 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -26,7 +26,7 @@ #include #include -#include "grpcpp/security/credentials.h" +#include "grpcpp/security/credentials_impl.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/security/credentials/credentials.h" @@ -36,9 +36,10 @@ #include "test/core/util/cmdline.h" static grpc_call_credentials* create_sts_creds(const char* json_file_path) { - grpc::experimental::StsCredentialsOptions options; + grpc_impl::experimental::StsCredentialsOptions options; if (strlen(json_file_path) == 0) { - auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); + auto status = + grpc_impl::experimental::StsCredentialsOptionsFromEnv(&options); if (!status.ok()) { gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); return nullptr; @@ -47,7 +48,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { grpc_slice sts_options_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(json_file_path, 1, &sts_options_slice))); - auto status = grpc::experimental::StsCredentialsOptionsFromJson( + auto status = grpc_impl::experimental::StsCredentialsOptionsFromJson( reinterpret_cast(GRPC_SLICE_START_PTR(sts_options_slice)), &options); gpr_slice_unref(sts_options_slice); @@ -57,7 +58,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { } } grpc_sts_credentials_options opts = - grpc::experimental::StsCredentialsCppToCoreOptions(options); + grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); grpc_call_credentials* result = grpc_sts_credentials_create(&opts, nullptr); return result; } diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index 9d6d25b21e5..7862cd0ecec 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -34,14 +34,15 @@ namespace { -typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; -typedef class ::grpc::experimental::TlsCredentialReloadArg +typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig + TlsKeyMaterialsConfig; +typedef class ::grpc_impl::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef struct ::grpc::experimental::TlsCredentialReloadInterface +typedef struct ::grpc_impl::experimental::TlsCredentialReloadInterface TlsCredentialReloadInterface; -typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef struct ::grpc::experimental::TlsServerAuthorizationCheckInterface +typedef struct ::grpc_impl::experimental::TlsServerAuthorizationCheckInterface TlsServerAuthorizationCheckInterface; static void tls_credential_reload_callback( @@ -130,7 +131,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsCppToCore) { options.actor_token_path = "/foo/baz"; options.actor_token_type = "even_nicer_token_type"; grpc_sts_credentials_options core_opts = - grpc::experimental::StsCredentialsCppToCoreOptions(options); + grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); EXPECT_EQ(options.token_exchange_service_uri, core_opts.token_exchange_service_uri); EXPECT_EQ(options.resource, core_opts.resource); @@ -270,7 +271,8 @@ TEST_F(CredentialsTest, StsCredentialsOptionsFromEnv) { gpr_unsetenv("STS_CREDENTIALS"); } -typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; +typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig + TlsKeyMaterialsConfig; TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) { std::shared_ptr config(new TlsKeyMaterialsConfig()); @@ -302,9 +304,9 @@ TEST_F(CredentialsTest, TlsKeyMaterialsModifiers) { EXPECT_STREQ(list[0].cert_chain.c_str(), "cert_chain"); } -typedef class ::grpc::experimental::TlsCredentialReloadArg +typedef class ::grpc_impl::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef class ::grpc::experimental::TlsCredentialReloadConfig +typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig TlsCredentialReloadConfig; TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) { @@ -431,9 +433,9 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) { delete config.c_config(); } -typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef class ::grpc::experimental::TlsServerAuthorizationCheckConfig +typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckConfig TlsServerAuthorizationCheckConfig; TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) { @@ -548,7 +550,8 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { delete config.c_config(); } -typedef class ::grpc::experimental::TlsCredentialsOptions TlsCredentialsOptions; +typedef class ::grpc_impl::experimental::TlsCredentialsOptions + TlsCredentialsOptions; TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) { std::shared_ptr key_materials_config( @@ -678,7 +681,7 @@ TEST_F(CredentialsTest, LoadTlsChannelCredentials) { TlsCredentialsOptions options = TlsCredentialsOptions( GRPC_TLS_SERVER_VERIFICATION, nullptr, credential_reload_config, server_authorization_check_config); - std::shared_ptr channel_credentials = + std::shared_ptr channel_credentials = grpc::experimental::TlsCredentials(options); GPR_ASSERT(channel_credentials.get() != nullptr); } diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index a4080632735..3ce6109b49d 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -940,6 +940,7 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ +include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -1023,6 +1024,7 @@ include/grpcpp/resource_quota.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ +include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index bcb79a23158..2dd2cb0c123 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -940,6 +940,7 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ +include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -1023,6 +1024,7 @@ include/grpcpp/resource_quota.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ +include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ From 6ccc298665428b833904945cfea67249abd7d264 Mon Sep 17 00:00:00 2001 From: Matthew Stevenson Date: Fri, 24 Jul 2020 11:28:29 -0700 Subject: [PATCH 23/45] Disable TLS 1.3-specific unit tests in ssl_transport_security_test.cc. --- test/core/tsi/ssl_transport_security_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 586200358ec..463f310d940 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -970,8 +970,7 @@ int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); grpc_init(); const size_t number_tls_versions = 2; - const tsi_tls_version tls_versions[] = {tsi_tls_version::TSI_TLS1_2, - tsi_tls_version::TSI_TLS1_3}; + const tsi_tls_version tls_versions[] = {tsi_tls_version::TSI_TLS1_2}; for (size_t i = 0; i < number_tls_versions; i++) { // Set the TLS version to be used in the tests. test_tls_version = tls_versions[i]; From 25d2b9b1020d1ea69d3dff9d4db3189daa168cc2 Mon Sep 17 00:00:00 2001 From: Matthew Stevenson Date: Fri, 24 Jul 2020 12:18:11 -0700 Subject: [PATCH 24/45] Fix number of TLS version tests to run. --- test/core/tsi/ssl_transport_security_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/tsi/ssl_transport_security_test.cc b/test/core/tsi/ssl_transport_security_test.cc index 463f310d940..a7e1b5215b7 100644 --- a/test/core/tsi/ssl_transport_security_test.cc +++ b/test/core/tsi/ssl_transport_security_test.cc @@ -969,7 +969,7 @@ void ssl_tsi_test_extract_cert_chain() { int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); grpc_init(); - const size_t number_tls_versions = 2; + const size_t number_tls_versions = 1; const tsi_tls_version tls_versions[] = {tsi_tls_version::TSI_TLS1_2}; for (size_t i = 0; i < number_tls_versions; i++) { // Set the TLS version to be used in the tests. From 1de0bfd9e2310a00cbb6467a8f3cb7fe6866c801 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Fri, 24 Jul 2020 12:47:33 -0700 Subject: [PATCH 25/45] Revert "Revert "Move create_channel and credentials from ::grpc_impl to ::grpc"" --- BUILD | 2 - BUILD.gn | 2 - CMakeLists.txt | 4 - Makefile | 4 - build_autogenerated.yaml | 4 - gRPC-C++.podspec | 2 - include/grpcpp/create_channel.h | 67 ++-- include/grpcpp/create_channel_impl.h | 78 ---- .../grpcpp/impl/codegen/client_context_impl.h | 13 +- include/grpcpp/security/credentials.h | 356 +++++++++++++----- include/grpcpp/security/credentials_impl.h | 356 ------------------ include/grpcpp/security/cronet_credentials.h | 5 +- include/grpcpp/security/server_credentials.h | 28 +- .../grpcpp/security/server_credentials_impl.h | 2 +- .../grpcpp/security/tls_credentials_options.h | 4 +- .../grpcpp/support/channel_arguments_impl.h | 5 +- src/cpp/client/client_context.cc | 2 +- src/cpp/client/create_channel.cc | 14 +- src/cpp/client/credentials_cc.cc | 4 +- src/cpp/client/cronet_credentials.cc | 5 +- src/cpp/client/insecure_credentials.cc | 4 +- src/cpp/client/secure_credentials.cc | 5 +- src/cpp/client/secure_credentials.h | 8 +- src/cpp/common/tls_credentials_options.cc | 4 +- .../common/tls_credentials_options_util.cc | 4 +- src/cpp/common/tls_credentials_options_util.h | 4 +- src/cpp/server/insecure_server_credentials.cc | 4 +- src/cpp/server/secure_server_credentials.cc | 6 +- src/cpp/server/secure_server_credentials.h | 13 +- test/core/security/fetch_oauth2.cc | 11 +- test/cpp/client/credentials_test.cc | 29 +- tools/doxygen/Doxyfile.c++ | 2 - tools/doxygen/Doxyfile.c++.internal | 2 - 33 files changed, 382 insertions(+), 671 deletions(-) delete mode 100644 include/grpcpp/create_channel_impl.h delete mode 100644 include/grpcpp/security/credentials_impl.h diff --git a/BUILD b/BUILD index 036c782ac30..0182416c493 100644 --- a/BUILD +++ b/BUILD @@ -225,7 +225,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", - "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", @@ -251,7 +250,6 @@ GRPCXX_PUBLIC_HDRS = [ "include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/credentials.h", - "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/BUILD.gn b/BUILD.gn index 59835609c50..b81612cd95a 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1093,7 +1093,6 @@ config("grpc_config") { "include/grpcpp/completion_queue.h", "include/grpcpp/completion_queue_impl.h", "include/grpcpp/create_channel.h", - "include/grpcpp/create_channel_impl.h", "include/grpcpp/create_channel_posix.h", "include/grpcpp/ext/health_check_service_server_builder_option.h", "include/grpcpp/generic/async_generic_service.h", @@ -1177,7 +1176,6 @@ config("grpc_config") { "include/grpcpp/security/auth_context.h", "include/grpcpp/security/auth_metadata_processor.h", "include/grpcpp/security/credentials.h", - "include/grpcpp/security/credentials_impl.h", "include/grpcpp/security/server_credentials.h", "include/grpcpp/security/server_credentials_impl.h", "include/grpcpp/security/tls_credentials_options.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b85e61f25a..89f151b79a6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2735,7 +2735,6 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h - include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h @@ -2819,7 +2818,6 @@ foreach(_hdr include/grpcpp/security/auth_context.h include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/credentials.h - include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h @@ -3429,7 +3427,6 @@ foreach(_hdr include/grpcpp/completion_queue.h include/grpcpp/completion_queue_impl.h include/grpcpp/create_channel.h - include/grpcpp/create_channel_impl.h include/grpcpp/create_channel_posix.h include/grpcpp/ext/health_check_service_server_builder_option.h include/grpcpp/generic/async_generic_service.h @@ -3513,7 +3510,6 @@ foreach(_hdr include/grpcpp/security/auth_context.h include/grpcpp/security/auth_metadata_processor.h include/grpcpp/security/credentials.h - include/grpcpp/security/credentials_impl.h include/grpcpp/security/server_credentials.h include/grpcpp/security/server_credentials_impl.h include/grpcpp/security/tls_credentials_options.h diff --git a/Makefile b/Makefile index 40e2642512c..146914f5c37 100644 --- a/Makefile +++ b/Makefile @@ -4885,7 +4885,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ - include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -4969,7 +4968,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ - include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ @@ -5577,7 +5575,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ - include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -5661,7 +5658,6 @@ PUBLIC_HEADERS_CXX += \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ - include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 0737db79647..5bf88a42be1 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -2068,7 +2068,6 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h - - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h @@ -2152,7 +2151,6 @@ libs: - include/grpcpp/security/auth_context.h - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/credentials.h - - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h @@ -2454,7 +2452,6 @@ libs: - include/grpcpp/completion_queue.h - include/grpcpp/completion_queue_impl.h - include/grpcpp/create_channel.h - - include/grpcpp/create_channel_impl.h - include/grpcpp/create_channel_posix.h - include/grpcpp/ext/health_check_service_server_builder_option.h - include/grpcpp/generic/async_generic_service.h @@ -2538,7 +2535,6 @@ libs: - include/grpcpp/security/auth_context.h - include/grpcpp/security/auth_metadata_processor.h - include/grpcpp/security/credentials.h - - include/grpcpp/security/credentials_impl.h - include/grpcpp/security/server_credentials.h - include/grpcpp/security/server_credentials_impl.h - include/grpcpp/security/tls_credentials_options.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index c1f21867f5e..2633038e47b 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -84,7 +84,6 @@ Pod::Spec.new do |s| 'include/grpcpp/completion_queue.h', 'include/grpcpp/completion_queue_impl.h', 'include/grpcpp/create_channel.h', - 'include/grpcpp/create_channel_impl.h', 'include/grpcpp/create_channel_posix.h', 'include/grpcpp/ext/health_check_service_server_builder_option.h', 'include/grpcpp/generic/async_generic_service.h', @@ -164,7 +163,6 @@ Pod::Spec.new do |s| 'include/grpcpp/security/auth_context.h', 'include/grpcpp/security/auth_metadata_processor.h', 'include/grpcpp/security/credentials.h', - 'include/grpcpp/security/credentials_impl.h', 'include/grpcpp/security/server_credentials.h', 'include/grpcpp/security/server_credentials_impl.h', 'include/grpcpp/security/tls_credentials_options.h', diff --git a/include/grpcpp/create_channel.h b/include/grpcpp/create_channel.h index bfd018b26f0..4b94a08e45e 100644 --- a/include/grpcpp/create_channel.h +++ b/include/grpcpp/create_channel.h @@ -1,6 +1,6 @@ /* * - * Copyright 2019 gRPC authors. + * Copyright 2015 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,36 +19,59 @@ #ifndef GRPCPP_CREATE_CHANNEL_H #define GRPCPP_CREATE_CHANNEL_H -#include +#include + +#include +#include +#include #include +#include namespace grpc { +/// Create a new \a Channel pointing to \a target. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +std::shared_ptr CreateChannel( + const grpc::string& target, + const std::shared_ptr& creds); -static inline std::shared_ptr<::grpc::Channel> CreateChannel( - const std::string& target, - const std::shared_ptr& creds) { - return ::grpc_impl::CreateChannelImpl(target, creds); -} - -static inline std::shared_ptr<::grpc::Channel> CreateCustomChannel( - const std::string& target, const std::shared_ptr& creds, - const ChannelArguments& args) { - return ::grpc_impl::CreateCustomChannelImpl(target, creds, args); -} +/// Create a new \em custom \a Channel pointing to \a target. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr CreateCustomChannel( + const grpc::string& target, + const std::shared_ptr& creds, + const ChannelArguments& args); namespace experimental { - -static inline std::shared_ptr<::grpc::Channel> -CreateCustomChannelWithInterceptors( - const std::string& target, const std::shared_ptr& creds, +/// Create a new \em custom \a Channel pointing to \a target with \a +/// interceptors being invoked per call. +/// +/// \warning For advanced use and testing ONLY. Override default channel +/// arguments only if necessary. +/// +/// \param target The URI of the endpoint to connect to. +/// \param creds Credentials to use for the created channel. If it does not +/// hold an object or is invalid, a lame channel (one on which all operations +/// fail) is returned. +/// \param args Options for channel creation. +std::shared_ptr CreateCustomChannelWithInterceptors( + const grpc::string& target, + const std::shared_ptr& creds, const ChannelArguments& args, std::vector< std::unique_ptr> - interceptor_creators) { - return ::grpc_impl::experimental::CreateCustomChannelWithInterceptors( - target, creds, args, std::move(interceptor_creators)); -} - + interceptor_creators); } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/create_channel_impl.h b/include/grpcpp/create_channel_impl.h deleted file mode 100644 index ac68728692c..00000000000 --- a/include/grpcpp/create_channel_impl.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Copyright 2015 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. - * - */ - -#ifndef GRPCPP_CREATE_CHANNEL_IMPL_H -#define GRPCPP_CREATE_CHANNEL_IMPL_H - -#include - -#include -#include -#include -#include -#include - -namespace grpc_impl { -/// Create a new \a Channel pointing to \a target. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -std::shared_ptr<::grpc::Channel> CreateChannelImpl( - const std::string& target, - const std::shared_ptr<::grpc::ChannelCredentials>& creds); - -/// Create a new \em custom \a Channel pointing to \a target. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr<::grpc::Channel> CreateCustomChannelImpl( - const std::string& target, - const std::shared_ptr<::grpc::ChannelCredentials>& creds, - const ::grpc::ChannelArguments& args); - -namespace experimental { -/// Create a new \em custom \a Channel pointing to \a target with \a -/// interceptors being invoked per call. -/// -/// \warning For advanced use and testing ONLY. Override default channel -/// arguments only if necessary. -/// -/// \param target The URI of the endpoint to connect to. -/// \param creds Credentials to use for the created channel. If it does not -/// hold an object or is invalid, a lame channel (one on which all operations -/// fail) is returned. -/// \param args Options for channel creation. -std::shared_ptr<::grpc::Channel> CreateCustomChannelWithInterceptors( - const std::string& target, - const std::shared_ptr& creds, - const ::grpc::ChannelArguments& args, - std::vector< - std::unique_ptr> - interceptor_creators); -} // namespace experimental -} // namespace grpc_impl - -#endif // GRPCPP_CREATE_CHANNEL_IMPL_H diff --git a/include/grpcpp/impl/codegen/client_context_impl.h b/include/grpcpp/impl/codegen/client_context_impl.h index 9b6d1755edb..2624e571cdb 100644 --- a/include/grpcpp/impl/codegen/client_context_impl.h +++ b/include/grpcpp/impl/codegen/client_context_impl.h @@ -58,6 +58,7 @@ struct grpc_call; namespace grpc { +class CallCredentials; class ChannelInterface; namespace internal { @@ -88,7 +89,6 @@ class ClientCallbackUnaryImpl; class ClientContextAccessor; } // namespace internal -class CallCredentials; class Channel; class CompletionQueue; class ServerContext; @@ -318,16 +318,15 @@ class ClientContext { /// /// It is legal to call this only before initial metadata is sent. /// - /// \see https://grpc.io/docs/guides/auth - void set_credentials( - const std::shared_ptr& creds); + /// \see https://grpc.io/docs/guides/auth.html + void set_credentials(const std::shared_ptr& creds); /// EXPERIMENTAL debugging API /// /// Returns the credentials for the client call. This should be used only in /// tests and for diagnostic purposes, and should not be used by application /// logic. - std::shared_ptr credentials() { return creds_; } + std::shared_ptr credentials() { return creds_; } /// Return the compression algorithm the client call will request be used. /// Note that the gRPC runtime may decide to ignore this request, for example, @@ -494,8 +493,8 @@ class ClientContext { grpc_call* call_; bool call_canceled_; gpr_timespec deadline_; - std::string authority_; - std::shared_ptr creds_; + grpc::string authority_; + std::shared_ptr creds_; mutable std::shared_ptr auth_context_; struct census_context* census_context_; std::multimap send_initial_metadata_; diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 45c6d55546f..b0da6650b6b 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -19,123 +19,301 @@ #ifndef GRPCPP_SECURITY_CREDENTIALS_H #define GRPCPP_SECURITY_CREDENTIALS_H -#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct grpc_call; namespace grpc { +class CallCredentials; +class SecureCallCredentials; +class SecureChannelCredentials; +class ChannelCredentials; -typedef ::grpc_impl::ChannelCredentials ChannelCredentials; -typedef ::grpc_impl::CallCredentials CallCredentials; -typedef ::grpc_impl::SslCredentialsOptions SslCredentialsOptions; -typedef ::grpc_impl::SecureCallCredentials SecureCallCredentials; -typedef ::grpc_impl::SecureChannelCredentials SecureChannelCredentials; -typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; +std::shared_ptr CreateCustomChannel( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args); -static inline std::shared_ptr -GoogleDefaultCredentials() { - return ::grpc_impl::GoogleDefaultCredentials(); +namespace experimental { +std::shared_ptr CreateCustomChannelWithInterceptors( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args, + std::vector< + std::unique_ptr> + interceptor_creators); } -static inline std::shared_ptr SslCredentials( - const SslCredentialsOptions& options) { - return ::grpc_impl::SslCredentials(options); -} +/// A channel credentials object encapsulates all the state needed by a client +/// to authenticate with a server for a given channel. +/// It can make various assertions, e.g., about the client’s identity, role +/// for all the calls on that channel. +/// +/// \see https://grpc.io/docs/guides/auth.html +class ChannelCredentials : private grpc::GrpcLibraryCodegen { + public: + ChannelCredentials(); + ~ChannelCredentials(); -static inline std::shared_ptr -GoogleComputeEngineCredentials() { - return ::grpc_impl::GoogleComputeEngineCredentials(); -} + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); -/// Constant for maximum auth token lifetime. -constexpr long kMaxAuthTokenLifetimeSecs = - ::grpc_impl::kMaxAuthTokenLifetimeSecs; + virtual SecureChannelCredentials* AsSecureCredentials() = 0; -static inline std::shared_ptr -ServiceAccountJWTAccessCredentials( - const std::string& json_key, - long token_lifetime_seconds = grpc::kMaxAuthTokenLifetimeSecs) { - return ::grpc_impl::ServiceAccountJWTAccessCredentials( - json_key, token_lifetime_seconds); -} + private: + friend std::shared_ptr CreateCustomChannel( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args); -static inline std::shared_ptr -GoogleRefreshTokenCredentials(const std::string& json_refresh_token) { - return ::grpc_impl::GoogleRefreshTokenCredentials(json_refresh_token); -} + friend std::shared_ptr + grpc::experimental::CreateCustomChannelWithInterceptors( + const grpc::string& target, + const std::shared_ptr& creds, + const grpc::ChannelArguments& args, + std::vector> + interceptor_creators); -static inline std::shared_ptr -AccessTokenCredentials(const std::string& access_token) { - return ::grpc_impl::AccessTokenCredentials(access_token); -} + virtual std::shared_ptr CreateChannelImpl( + const grpc::string& target, const ChannelArguments& args) = 0; -static inline std::shared_ptr GoogleIAMCredentials( - const std::string& authorization_token, - const std::string& authority_selector) { - return ::grpc_impl::GoogleIAMCredentials(authorization_token, - authority_selector); -} + // This function should have been a pure virtual function, but it is + // implemented as a virtual function so that it does not break API. + virtual std::shared_ptr CreateChannelWithInterceptors( + const grpc::string& /*target*/, const ChannelArguments& /*args*/, + std::vector> + /*interceptor_creators*/) { + return nullptr; + } +}; + +/// A call credentials object encapsulates the state needed by a client to +/// authenticate with a server for a given call on a channel. +/// +/// \see https://grpc.io/docs/guides/auth.html +class CallCredentials : private grpc::GrpcLibraryCodegen { + public: + CallCredentials(); + ~CallCredentials(); + + /// Apply this instance's credentials to \a call. + virtual bool ApplyToCall(grpc_call* call) = 0; + virtual grpc::string DebugString() { + return "CallCredentials did not provide a debug string"; + } + + protected: + friend std::shared_ptr CompositeChannelCredentials( + const std::shared_ptr& channel_creds, + const std::shared_ptr& call_creds); + + friend std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); + + virtual SecureCallCredentials* AsSecureCredentials() = 0; +}; + +/// Options used to build SslCredentials. +struct SslCredentialsOptions { + /// The buffer containing the PEM encoding of the server root certificates. If + /// this parameter is empty, the default roots will be used. The default + /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH + /// environment variable pointing to a file on the file system containing the + /// roots. + grpc::string pem_root_certs; + + /// The buffer containing the PEM encoding of the client's private key. This + /// parameter can be empty if the client does not have a private key. + grpc::string pem_private_key; + + /// The buffer containing the PEM encoding of the client's certificate chain. + /// This parameter can be empty if the client does not have a certificate + /// chain. + grpc::string pem_cert_chain; +}; + +// Factories for building different types of Credentials The functions may +// return empty shared_ptr when credentials cannot be created. If a +// Credentials pointer is returned, it can still be invalid when used to create +// a channel. A lame channel will be created then and all rpcs will fail on it. + +/// Builds credentials with reasonable defaults. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleDefaultCredentials(); + +/// Builds SSL Credentials given SSL specific options +std::shared_ptr SslCredentials( + const SslCredentialsOptions& options); + +/// Builds credentials for use when running in GCE +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleComputeEngineCredentials(); -static inline std::shared_ptr CompositeChannelCredentials( +constexpr long kMaxAuthTokenLifetimeSecs = 3600; + +/// Builds Service Account JWT Access credentials. +/// json_key is the JSON key string containing the client's private key. +/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token +/// (JWT) created with this credentials. It should not exceed +/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. +std::shared_ptr ServiceAccountJWTAccessCredentials( + const grpc::string& json_key, + long token_lifetime_seconds = kMaxAuthTokenLifetimeSecs); + +/// Builds refresh token credentials. +/// json_refresh_token is the JSON string containing the refresh token along +/// with a client_id and client_secret. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleRefreshTokenCredentials( + const grpc::string& json_refresh_token); + +/// Builds access token credentials. +/// access_token is an oauth2 access token that was fetched using an out of band +/// mechanism. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr AccessTokenCredentials( + const grpc::string& access_token); + +/// Builds IAM credentials. +/// +/// \warning Only use these credentials when connecting to a Google endpoint. +/// Using these credentials to connect to any other service may result in this +/// service being able to impersonate your client for requests to Google +/// services. +std::shared_ptr GoogleIAMCredentials( + const grpc::string& authorization_token, + const grpc::string& authority_selector); + +/// Combines a channel credentials and a call credentials into a composite +/// channel credentials. +std::shared_ptr CompositeChannelCredentials( const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds) { - return ::grpc_impl::CompositeChannelCredentials(channel_creds, call_creds); -} + const std::shared_ptr& call_creds); -static inline std::shared_ptr -CompositeCallCredentials(const std::shared_ptr& creds1, - const std::shared_ptr& creds2) { - return ::grpc_impl::CompositeCallCredentials(creds1, creds2); -} +/// Combines two call credentials objects into a composite call credentials. +std::shared_ptr CompositeCallCredentials( + const std::shared_ptr& creds1, + const std::shared_ptr& creds2); -static inline std::shared_ptr -InsecureChannelCredentials() { - return ::grpc_impl::InsecureChannelCredentials(); -} +/// Credentials for an unencrypted, unauthenticated channel +std::shared_ptr InsecureChannelCredentials(); -typedef ::grpc_impl::MetadataCredentialsPlugin MetadataCredentialsPlugin; +/// User defined metadata credentials. +class MetadataCredentialsPlugin { + public: + virtual ~MetadataCredentialsPlugin() {} -static inline std::shared_ptr -MetadataCredentialsFromPlugin( - std::unique_ptr plugin) { - return ::grpc_impl::MetadataCredentialsFromPlugin(std::move(plugin)); -} + /// If this method returns true, the Process function will be scheduled in + /// a different thread from the one processing the call. + virtual bool IsBlocking() const { return true; } + + /// Type of credentials this plugin is implementing. + virtual const char* GetType() const { return ""; } + + /// Gets the auth metatada produced by this plugin. + /// The fully qualified method name is: + /// service_url + "/" + method_name. + /// The channel_auth_context contains (among other things), the identity of + /// the server. + virtual grpc::Status GetMetadata( + grpc::string_ref service_url, grpc::string_ref method_name, + const grpc::AuthContext& channel_auth_context, + std::multimap* metadata) = 0; + + virtual grpc::string DebugString() { + return "MetadataCredentialsPlugin did not provide a debug string"; + } +}; + +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin); namespace experimental { -typedef ::grpc_impl::experimental::StsCredentialsOptions StsCredentialsOptions; +/// Options for creating STS Oauth Token Exchange credentials following the IETF +/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. +/// Optional fields may be set to empty string. It is the responsibility of the +/// caller to ensure that the subject and actor tokens are refreshed on disk at +/// the specified paths. +struct StsCredentialsOptions { + grpc::string token_exchange_service_uri; // Required. + grpc::string resource; // Optional. + grpc::string audience; // Optional. + grpc::string scope; // Optional. + grpc::string requested_token_type; // Optional. + grpc::string subject_token_path; // Required. + grpc::string subject_token_type; // Required. + grpc::string actor_token_path; // Optional. + grpc::string actor_token_type; // Optional. +}; -static inline grpc::Status StsCredentialsOptionsFromJson( - const std::string& json_string, StsCredentialsOptions* options) { - return ::grpc_impl::experimental::StsCredentialsOptionsFromJson(json_string, - options); -} +grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, + StsCredentialsOptions* options); -static inline grpc::Status StsCredentialsOptionsFromEnv( - StsCredentialsOptions* options) { - return grpc_impl::experimental::StsCredentialsOptionsFromEnv(options); -} +/// Creates STS credentials options from the $STS_CREDENTIALS environment +/// variable. This environment variable points to the path of a JSON file +/// comforming to the schema described above. +grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); -static inline std::shared_ptr StsCredentials( - const StsCredentialsOptions& options) { - return grpc_impl::experimental::StsCredentials(options); -} +std::shared_ptr StsCredentials( + const StsCredentialsOptions& options); -typedef ::grpc_impl::experimental::AltsCredentialsOptions - AltsCredentialsOptions; +std::shared_ptr MetadataCredentialsFromPlugin( + std::unique_ptr plugin, + grpc_security_level min_security_level); -static inline std::shared_ptr AltsCredentials( - const AltsCredentialsOptions& options) { - return ::grpc_impl::experimental::AltsCredentials(options); -} +/// Options used to build AltsCredentials. +struct AltsCredentialsOptions { + /// service accounts of target endpoint that will be acceptable + /// by the client. If service accounts are provided and none of them matches + /// that of the server, authentication will fail. + std::vector target_service_accounts; +}; -static inline std::shared_ptr LocalCredentials( - grpc_local_connect_type type) { - return ::grpc_impl::experimental::LocalCredentials(type); -} +/// Builds ALTS Credentials given ALTS specific options +std::shared_ptr AltsCredentials( + const AltsCredentialsOptions& options); -static inline std::shared_ptr TlsCredentials( - const ::grpc_impl::experimental::TlsCredentialsOptions& options) { - return ::grpc_impl::experimental::TlsCredentials(options); -} +/// Builds Local Credentials. +std::shared_ptr LocalCredentials( + grpc_local_connect_type type); + +/// Builds TLS Credentials given TLS options. +std::shared_ptr TlsCredentials( + const TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/credentials_impl.h b/include/grpcpp/security/credentials_impl.h deleted file mode 100644 index 84206a688bc..00000000000 --- a/include/grpcpp/security/credentials_impl.h +++ /dev/null @@ -1,356 +0,0 @@ -/* - * - * Copyright 2015 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. - * - */ - -#ifndef GRPCPP_SECURITY_CREDENTIALS_IMPL_H -#define GRPCPP_SECURITY_CREDENTIALS_IMPL_H - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct grpc_call; - -namespace grpc_impl { - -class ChannelCredentials; -class CallCredentials; -class SecureCallCredentials; -class SecureChannelCredentials; - -std::shared_ptr CreateCustomChannelImpl( - const std::string& target, const std::shared_ptr& creds, - const ChannelArguments& args); - -namespace experimental { -std::shared_ptr CreateCustomChannelWithInterceptors( - const std::string& target, const std::shared_ptr& creds, - const ChannelArguments& args, - std::vector< - std::unique_ptr> - interceptor_creators); -} - -/// A channel credentials object encapsulates all the state needed by a client -/// to authenticate with a server for a given channel. -/// It can make various assertions, e.g., about the client’s identity, role -/// for all the calls on that channel. -/// -/// \see https://grpc.io/docs/guides/auth -class ChannelCredentials : private grpc::GrpcLibraryCodegen { - public: - ChannelCredentials(); - ~ChannelCredentials(); - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - virtual SecureChannelCredentials* AsSecureCredentials() = 0; - - private: - friend std::shared_ptr CreateCustomChannelImpl( - const std::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args); - - friend std::shared_ptr - grpc_impl::experimental::CreateCustomChannelWithInterceptors( - const std::string& target, - const std::shared_ptr& creds, - const ChannelArguments& args, - std::vector> - interceptor_creators); - - virtual std::shared_ptr CreateChannelImpl( - const std::string& target, const ChannelArguments& args) = 0; - - // This function should have been a pure virtual function, but it is - // implemented as a virtual function so that it does not break API. - virtual std::shared_ptr CreateChannelWithInterceptors( - const std::string& /*target*/, const ChannelArguments& /*args*/, - std::vector> - /*interceptor_creators*/) { - return nullptr; - } -}; - -/// A call credentials object encapsulates the state needed by a client to -/// authenticate with a server for a given call on a channel. -/// -/// \see https://grpc.io/docs/guides/auth -class CallCredentials : private grpc::GrpcLibraryCodegen { - public: - CallCredentials(); - ~CallCredentials(); - - /// Apply this instance's credentials to \a call. - virtual bool ApplyToCall(grpc_call* call) = 0; - virtual std::string DebugString() { - return "CallCredentials did not provide a debug string"; - } - - protected: - friend std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - - friend std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - - virtual SecureCallCredentials* AsSecureCredentials() = 0; -}; - -/// Options used to build SslCredentials. -struct SslCredentialsOptions { - /// The buffer containing the PEM encoding of the server root certificates. If - /// this parameter is empty, the default roots will be used. The default - /// roots can be overridden using the \a GRPC_DEFAULT_SSL_ROOTS_FILE_PATH - /// environment variable pointing to a file on the file system containing the - /// roots. - std::string pem_root_certs; - - /// The buffer containing the PEM encoding of the client's private key. This - /// parameter can be empty if the client does not have a private key. - std::string pem_private_key; - - /// The buffer containing the PEM encoding of the client's certificate chain. - /// This parameter can be empty if the client does not have a certificate - /// chain. - std::string pem_cert_chain; -}; - -// Factories for building different types of Credentials The functions may -// return empty shared_ptr when credentials cannot be created. If a -// Credentials pointer is returned, it can still be invalid when used to create -// a channel. A lame channel will be created then and all rpcs will fail on it. - -/// Builds credentials with reasonable defaults. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleDefaultCredentials(); - -/// Builds SSL Credentials given SSL specific options -std::shared_ptr SslCredentials( - const SslCredentialsOptions& options); - -/// Builds credentials for use when running in GCE -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleComputeEngineCredentials(); - -constexpr long kMaxAuthTokenLifetimeSecs = 3600; - -/// Builds Service Account JWT Access credentials. -/// json_key is the JSON key string containing the client's private key. -/// token_lifetime_seconds is the lifetime in seconds of each Json Web Token -/// (JWT) created with this credentials. It should not exceed -/// \a kMaxAuthTokenLifetimeSecs or will be cropped to this value. -std::shared_ptr ServiceAccountJWTAccessCredentials( - const std::string& json_key, - long token_lifetime_seconds = grpc_impl::kMaxAuthTokenLifetimeSecs); - -/// Builds refresh token credentials. -/// json_refresh_token is the JSON string containing the refresh token along -/// with a client_id and client_secret. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleRefreshTokenCredentials( - const std::string& json_refresh_token); - -/// Builds access token credentials. -/// access_token is an oauth2 access token that was fetched using an out of band -/// mechanism. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr AccessTokenCredentials( - const std::string& access_token); - -/// Builds IAM credentials. -/// -/// \warning Only use these credentials when connecting to a Google endpoint. -/// Using these credentials to connect to any other service may result in this -/// service being able to impersonate your client for requests to Google -/// services. -std::shared_ptr GoogleIAMCredentials( - const std::string& authorization_token, - const std::string& authority_selector); - -/// Combines a channel credentials and a call credentials into a composite -/// channel credentials. -std::shared_ptr CompositeChannelCredentials( - const std::shared_ptr& channel_creds, - const std::shared_ptr& call_creds); - -/// Combines two call credentials objects into a composite call credentials. -std::shared_ptr CompositeCallCredentials( - const std::shared_ptr& creds1, - const std::shared_ptr& creds2); - -/// Credentials for an unencrypted, unauthenticated channel -std::shared_ptr InsecureChannelCredentials(); - -/// User defined metadata credentials. -class MetadataCredentialsPlugin { - public: - virtual ~MetadataCredentialsPlugin() {} - - /// If this method returns true, the Process function will be scheduled in - /// a different thread from the one processing the call. - virtual bool IsBlocking() const { return true; } - - /// Type of credentials this plugin is implementing. - virtual const char* GetType() const { return ""; } - - /// Gets the auth metatada produced by this plugin. - /// The fully qualified method name is: - /// service_url + "/" + method_name. - /// The channel_auth_context contains (among other things), the identity of - /// the server. - virtual grpc::Status GetMetadata( - grpc::string_ref service_url, grpc::string_ref method_name, - const grpc::AuthContext& channel_auth_context, - std::multimap* metadata) = 0; - - virtual std::string DebugString() { - return "MetadataCredentialsPlugin did not provide a debug string"; - } -}; - -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin); - -namespace experimental { - -/// Options for creating STS Oauth Token Exchange credentials following the IETF -/// draft https://tools.ietf.org/html/draft-ietf-oauth-token-exchange-16. -/// Optional fields may be set to empty string. It is the responsibility of the -/// caller to ensure that the subject and actor tokens are refreshed on disk at -/// the specified paths. -struct StsCredentialsOptions { - std::string token_exchange_service_uri; // Required. - std::string resource; // Optional. - std::string audience; // Optional. - std::string scope; // Optional. - std::string requested_token_type; // Optional. - std::string subject_token_path; // Required. - std::string subject_token_type; // Required. - std::string actor_token_path; // Optional. - std::string actor_token_type; // Optional. -}; - -/// Creates STS Options from a JSON string. The JSON schema is as follows: -/// { -/// "title": "STS Credentials Config", -/// "type": "object", -/// "required": ["token_exchange_service_uri", "subject_token_path", -/// "subject_token_type"], -/// "properties": { -/// "token_exchange_service_uri": { -/// "type": "string" -/// }, -/// "resource": { -/// "type": "string" -/// }, -/// "audience": { -/// "type": "string" -/// }, -/// "scope": { -/// "type": "string" -/// }, -/// "requested_token_type": { -/// "type": "string" -/// }, -/// "subject_token_path": { -/// "type": "string" -/// }, -/// "subject_token_type": { -/// "type": "string" -/// }, -/// "actor_token_path" : { -/// "type": "string" -/// }, -/// "actor_token_type": { -/// "type": "string" -/// } -/// } -/// } -grpc::Status StsCredentialsOptionsFromJson(const std::string& json_string, - StsCredentialsOptions* options); - -/// Creates STS credentials options from the $STS_CREDENTIALS environment -/// variable. This environment variable points to the path of a JSON file -/// comforming to the schema described above. -grpc::Status StsCredentialsOptionsFromEnv(StsCredentialsOptions* options); - -std::shared_ptr StsCredentials( - const StsCredentialsOptions& options); - -std::shared_ptr MetadataCredentialsFromPlugin( - std::unique_ptr plugin, - grpc_security_level min_security_level); - -/// Options used to build AltsCredentials. -struct AltsCredentialsOptions { - /// service accounts of target endpoint that will be acceptable - /// by the client. If service accounts are provided and none of them matches - /// that of the server, authentication will fail. - std::vector target_service_accounts; -}; - -/// Builds ALTS Credentials given ALTS specific options -std::shared_ptr AltsCredentials( - const AltsCredentialsOptions& options); - -/// Builds Local Credentials. -std::shared_ptr LocalCredentials( - grpc_local_connect_type type); - -/// Builds TLS Credentials given TLS options. -std::shared_ptr TlsCredentials( - const TlsCredentialsOptions& options); - -} // namespace experimental -} // namespace grpc_impl - -#endif // GRPCPP_SECURITY_CREDENTIALS_IMPL_H diff --git a/include/grpcpp/security/cronet_credentials.h b/include/grpcpp/security/cronet_credentials.h index 008570b8cdf..81d3200e705 100644 --- a/include/grpcpp/security/cronet_credentials.h +++ b/include/grpcpp/security/cronet_credentials.h @@ -23,10 +23,7 @@ namespace grpc { -static inline std::shared_ptr -CronetChannelCredentials(void* engine) { - return ::grpc_impl::CronetChannelCredentials(engine); -} +std::shared_ptr CronetChannelCredentials(void* engine); } // namespace grpc diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index 5228ac138cc..1223b10978e 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -55,35 +55,25 @@ struct SslServerCredentialsOptions { grpc_ssl_client_certificate_request_type client_certificate_request; }; -static inline std::shared_ptr SslServerCredentials( - const SslServerCredentialsOptions& options) { - return ::grpc_impl::SslServerCredentials(options); -} +std::shared_ptr SslServerCredentials( + const SslServerCredentialsOptions& options); -static inline std::shared_ptr InsecureServerCredentials() { - return ::grpc_impl::InsecureServerCredentials(); -} +std::shared_ptr InsecureServerCredentials(); namespace experimental { typedef ::grpc_impl::experimental::AltsServerCredentialsOptions AltsServerCredentialsOptions; -static inline std::shared_ptr AltsServerCredentials( - const AltsServerCredentialsOptions& options) { - return ::grpc_impl::experimental::AltsServerCredentials(options); -} +std::shared_ptr AltsServerCredentials( + const AltsServerCredentialsOptions& options); -static inline std::shared_ptr LocalServerCredentials( - grpc_local_connect_type type) { - return ::grpc_impl::experimental::LocalServerCredentials(type); -} +std::shared_ptr LocalServerCredentials( + grpc_local_connect_type type); /// Builds TLS ServerCredentials given TLS options. -static inline std::shared_ptr TlsServerCredentials( - const ::grpc_impl::experimental::TlsCredentialsOptions& options) { - return ::grpc_impl::experimental::TlsServerCredentials(options); -} +std::shared_ptr TlsServerCredentials( + const ::grpc::experimental::TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/server_credentials_impl.h b/include/grpcpp/security/server_credentials_impl.h index 7e9e784f6e5..734409ab8e5 100644 --- a/include/grpcpp/security/server_credentials_impl.h +++ b/include/grpcpp/security/server_credentials_impl.h @@ -81,7 +81,7 @@ std::shared_ptr LocalServerCredentials( /// Builds TLS ServerCredentials given TLS options. std::shared_ptr TlsServerCredentials( - const TlsCredentialsOptions& options); + const grpc::experimental::TlsCredentialsOptions& options); } // namespace experimental } // namespace grpc_impl diff --git a/include/grpcpp/security/tls_credentials_options.h b/include/grpcpp/security/tls_credentials_options.h index 8df44e37f93..9613e2f69ba 100644 --- a/include/grpcpp/security/tls_credentials_options.h +++ b/include/grpcpp/security/tls_credentials_options.h @@ -36,7 +36,7 @@ typedef struct grpc_tls_server_authorization_check_config grpc_tls_server_authorization_check_config; typedef struct grpc_tls_credentials_options grpc_tls_credentials_options; -namespace grpc_impl { +namespace grpc { namespace experimental { /** TLS key materials config, wrapper for grpc_tls_key_materials_config. It is @@ -340,6 +340,6 @@ class TlsCredentialsOptions { }; } // namespace experimental -} // namespace grpc_impl +} // namespace grpc #endif // GRPCPP_SECURITY_TLS_CREDENTIALS_OPTIONS_H diff --git a/include/grpcpp/support/channel_arguments_impl.h b/include/grpcpp/support/channel_arguments_impl.h index e526f72f177..28cb0cef082 100644 --- a/include/grpcpp/support/channel_arguments_impl.h +++ b/include/grpcpp/support/channel_arguments_impl.h @@ -28,6 +28,7 @@ #include namespace grpc { +class SecureChannelCredentials; namespace testing { class ChannelArgumentsTest; } // namespace testing @@ -35,8 +36,6 @@ class ChannelArgumentsTest; namespace grpc_impl { -class SecureChannelCredentials; - /// Options for channel creation. The user can use generic setters to pass /// key value pairs down to C channel creation code. For gRPC related options, /// concrete setters are provided. @@ -126,7 +125,7 @@ class ChannelArguments { } private: - friend class grpc_impl::SecureChannelCredentials; + friend class grpc::SecureChannelCredentials; friend class grpc::testing::ChannelArgumentsTest; /// Default pointer argument operations. diff --git a/src/cpp/client/client_context.cc b/src/cpp/client/client_context.cc index 8642799e905..d0ec597fc63 100644 --- a/src/cpp/client/client_context.cc +++ b/src/cpp/client/client_context.cc @@ -73,7 +73,7 @@ ClientContext::~ClientContext() { } void ClientContext::set_credentials( - const std::shared_ptr& creds) { + const std::shared_ptr& creds) { creds_ = creds; // If call_ is set, we have already created the call, and set the call // credentials. This should only be done before we have started the batch diff --git a/src/cpp/client/create_channel.cc b/src/cpp/client/create_channel.cc index 2bbeebc2df6..48831d0fede 100644 --- a/src/cpp/client/create_channel.cc +++ b/src/cpp/client/create_channel.cc @@ -26,15 +26,15 @@ #include "src/cpp/client/create_channel_internal.h" -namespace grpc_impl { -std::shared_ptr CreateChannelImpl( - const std::string& target, +namespace grpc { +std::shared_ptr CreateChannel( + const grpc::string& target, const std::shared_ptr& creds) { - return CreateCustomChannelImpl(target, creds, grpc::ChannelArguments()); + return CreateCustomChannel(target, creds, grpc::ChannelArguments()); } -std::shared_ptr CreateCustomChannelImpl( - const std::string& target, +std::shared_ptr CreateCustomChannel( + const grpc::string& target, const std::shared_ptr& creds, const grpc::ChannelArguments& args) { grpc::GrpcLibraryCodegen @@ -82,4 +82,4 @@ std::shared_ptr CreateCustomChannelWithInterceptors( } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/credentials_cc.cc b/src/cpp/client/credentials_cc.cc index 62334bd9eba..9dfb2f491ca 100644 --- a/src/cpp/client/credentials_cc.cc +++ b/src/cpp/client/credentials_cc.cc @@ -19,7 +19,7 @@ #include #include -namespace grpc_impl { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; ChannelCredentials::ChannelCredentials() { g_gli_initializer.summon(); } @@ -30,4 +30,4 @@ CallCredentials::CallCredentials() { g_gli_initializer.summon(); } CallCredentials::~CallCredentials() {} -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/cronet_credentials.cc b/src/cpp/client/cronet_credentials.cc index f4ead14cde8..d09e2841279 100644 --- a/src/cpp/client/cronet_credentials.cc +++ b/src/cpp/client/cronet_credentials.cc @@ -55,10 +55,9 @@ class CronetChannelCredentialsImpl final : public ChannelCredentials { } void* engine_; }; -} // namespace grpc -namespace grpc_impl { + std::shared_ptr CronetChannelCredentials(void* engine) { return std::shared_ptr( new grpc::CronetChannelCredentialsImpl(engine)); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/insecure_credentials.cc b/src/cpp/client/insecure_credentials.cc index 0495b9378b0..a9be08d5a10 100644 --- a/src/cpp/client/insecure_credentials.cc +++ b/src/cpp/client/insecure_credentials.cc @@ -24,7 +24,7 @@ #include #include "src/cpp/client/create_channel_internal.h" -namespace grpc_impl { +namespace grpc { namespace { class InsecureChannelCredentialsImpl final : public ChannelCredentials { @@ -59,4 +59,4 @@ std::shared_ptr InsecureChannelCredentials() { new InsecureChannelCredentialsImpl()); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 108762e76ab..378cceaa114 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -38,7 +38,7 @@ #include "src/cpp/client/create_channel_internal.h" #include "src/cpp/common/secure_auth_context.h" -namespace grpc_impl { +namespace grpc { static grpc::internal::GrpcLibraryInitializer g_gli_initializer; SecureChannelCredentials::SecureChannelCredentials( @@ -388,9 +388,6 @@ std::shared_ptr MetadataCredentialsFromPlugin( c_plugin, GRPC_PRIVACY_AND_INTEGRITY, nullptr)); } -} // namespace grpc_impl - -namespace grpc { namespace { void DeleteWrapper(void* wrapper, grpc_error* /*ignored*/) { MetadataCredentialsPluginWrapper* w = diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 9238738146d..7d36de2adcc 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -33,6 +32,9 @@ namespace grpc_impl { class Channel; +} // namespace grpc_impl + +namespace grpc { class SecureChannelCredentials final : public ChannelCredentials { public: @@ -85,10 +87,6 @@ grpc_sts_credentials_options StsCredentialsCppToCoreOptions( } // namespace experimental -} // namespace grpc_impl - -namespace grpc { - class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); diff --git a/src/cpp/common/tls_credentials_options.cc b/src/cpp/common/tls_credentials_options.cc index a9122e962d3..011cf4b3e5d 100644 --- a/src/cpp/common/tls_credentials_options.cc +++ b/src/cpp/common/tls_credentials_options.cc @@ -23,7 +23,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** TLS key materials config API implementation **/ @@ -340,4 +340,4 @@ TlsCredentialsOptions::TlsCredentialsOptions( TlsCredentialsOptions::~TlsCredentialsOptions() {} } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/common/tls_credentials_options_util.cc b/src/cpp/common/tls_credentials_options_util.cc index 2211460e664..51cc4e2aefa 100644 --- a/src/cpp/common/tls_credentials_options_util.cc +++ b/src/cpp/common/tls_credentials_options_util.cc @@ -21,7 +21,7 @@ #include #include "src/cpp/common/tls_credentials_options_util.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** Converts the Cpp key materials to C key materials; this allocates memory for @@ -146,4 +146,4 @@ void TlsServerAuthorizationCheckArgDestroyContext(void* context) { } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/common/tls_credentials_options_util.h b/src/cpp/common/tls_credentials_options_util.h index 93e94562398..4ee04d15d7f 100644 --- a/src/cpp/common/tls_credentials_options_util.h +++ b/src/cpp/common/tls_credentials_options_util.h @@ -24,7 +24,7 @@ #include "src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h" -namespace grpc_impl { +namespace grpc { namespace experimental { /** The following function is exposed for testing purposes. **/ @@ -53,6 +53,6 @@ void TlsCredentialReloadArgDestroyContext(void* context); void TlsServerAuthorizationCheckArgDestroyContext(void* context); } // namespace experimental -} // namespace grpc_impl +} // namespace grpc #endif // GRPC_INTERNAL_CPP_COMMON_TLS_CREDENTIALS_OPTIONS_UTIL_H diff --git a/src/cpp/server/insecure_server_credentials.cc b/src/cpp/server/insecure_server_credentials.cc index bc908920b8d..04e5435efb9 100644 --- a/src/cpp/server/insecure_server_credentials.cc +++ b/src/cpp/server/insecure_server_credentials.cc @@ -21,7 +21,7 @@ #include #include -namespace grpc_impl { +namespace grpc { namespace { class InsecureServerCredentialsImpl final : public ServerCredentials { public: @@ -41,4 +41,4 @@ std::shared_ptr InsecureServerCredentials() { new InsecureServerCredentialsImpl()); } -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index f94696fd767..48fb3ad9f34 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -94,7 +94,7 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( } // namespace grpc -namespace grpc_impl { +namespace grpc { int SecureServerCredentials::AddPortToServer(const std::string& addr, grpc_server* server) { @@ -149,11 +149,11 @@ std::shared_ptr LocalServerCredentials( } std::shared_ptr TlsServerCredentials( - const TlsCredentialsOptions& options) { + const grpc::experimental::TlsCredentialsOptions& options) { grpc::GrpcLibraryCodegen init; return std::shared_ptr(new SecureServerCredentials( grpc_tls_server_credentials_create(options.c_credentials_options()))); } } // namespace experimental -} // namespace grpc_impl +} // namespace grpc diff --git a/src/cpp/server/secure_server_credentials.h b/src/cpp/server/secure_server_credentials.h index 9e9e33579f0..407d70766b5 100644 --- a/src/cpp/server/secure_server_credentials.h +++ b/src/cpp/server/secure_server_credentials.h @@ -28,14 +28,9 @@ #include "src/cpp/server/thread_pool_interface.h" -namespace grpc_impl { - -class SecureServerCredentials; -} // namespace grpc_impl - namespace grpc { -typedef ::grpc_impl::SecureServerCredentials SecureServerCredentials; +class SecureServerCredentials; class AuthMetadataProcessorAyncWrapper final { public: @@ -61,10 +56,6 @@ class AuthMetadataProcessorAyncWrapper final { std::shared_ptr processor_; }; -} // namespace grpc - -namespace grpc_impl { - class SecureServerCredentials final : public ServerCredentials { public: explicit SecureServerCredentials(grpc_server_credentials* creds) @@ -83,6 +74,6 @@ class SecureServerCredentials final : public ServerCredentials { std::unique_ptr processor_; }; -} // namespace grpc_impl +} // namespace grpc #endif // GRPC_INTERNAL_CPP_SERVER_SECURE_SERVER_CREDENTIALS_H diff --git a/test/core/security/fetch_oauth2.cc b/test/core/security/fetch_oauth2.cc index 1aa999758b0..99d7c76d0d3 100644 --- a/test/core/security/fetch_oauth2.cc +++ b/test/core/security/fetch_oauth2.cc @@ -26,7 +26,7 @@ #include #include -#include "grpcpp/security/credentials_impl.h" +#include "grpcpp/security/credentials.h" #include "src/core/lib/iomgr/error.h" #include "src/core/lib/iomgr/load_file.h" #include "src/core/lib/security/credentials/credentials.h" @@ -36,10 +36,9 @@ #include "test/core/util/cmdline.h" static grpc_call_credentials* create_sts_creds(const char* json_file_path) { - grpc_impl::experimental::StsCredentialsOptions options; + grpc::experimental::StsCredentialsOptions options; if (strlen(json_file_path) == 0) { - auto status = - grpc_impl::experimental::StsCredentialsOptionsFromEnv(&options); + auto status = grpc::experimental::StsCredentialsOptionsFromEnv(&options); if (!status.ok()) { gpr_log(GPR_ERROR, "%s", status.error_message().c_str()); return nullptr; @@ -48,7 +47,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { grpc_slice sts_options_slice; GPR_ASSERT(GRPC_LOG_IF_ERROR( "load_file", grpc_load_file(json_file_path, 1, &sts_options_slice))); - auto status = grpc_impl::experimental::StsCredentialsOptionsFromJson( + auto status = grpc::experimental::StsCredentialsOptionsFromJson( reinterpret_cast(GRPC_SLICE_START_PTR(sts_options_slice)), &options); gpr_slice_unref(sts_options_slice); @@ -58,7 +57,7 @@ static grpc_call_credentials* create_sts_creds(const char* json_file_path) { } } grpc_sts_credentials_options opts = - grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); + grpc::experimental::StsCredentialsCppToCoreOptions(options); grpc_call_credentials* result = grpc_sts_credentials_create(&opts, nullptr); return result; } diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc index 7862cd0ecec..9d6d25b21e5 100644 --- a/test/cpp/client/credentials_test.cc +++ b/test/cpp/client/credentials_test.cc @@ -34,15 +34,14 @@ namespace { -typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig - TlsKeyMaterialsConfig; -typedef class ::grpc_impl::experimental::TlsCredentialReloadArg +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; +typedef class ::grpc::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef struct ::grpc_impl::experimental::TlsCredentialReloadInterface +typedef struct ::grpc::experimental::TlsCredentialReloadInterface TlsCredentialReloadInterface; -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef struct ::grpc_impl::experimental::TlsServerAuthorizationCheckInterface +typedef struct ::grpc::experimental::TlsServerAuthorizationCheckInterface TlsServerAuthorizationCheckInterface; static void tls_credential_reload_callback( @@ -131,7 +130,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsCppToCore) { options.actor_token_path = "/foo/baz"; options.actor_token_type = "even_nicer_token_type"; grpc_sts_credentials_options core_opts = - grpc_impl::experimental::StsCredentialsCppToCoreOptions(options); + grpc::experimental::StsCredentialsCppToCoreOptions(options); EXPECT_EQ(options.token_exchange_service_uri, core_opts.token_exchange_service_uri); EXPECT_EQ(options.resource, core_opts.resource); @@ -271,8 +270,7 @@ TEST_F(CredentialsTest, StsCredentialsOptionsFromEnv) { gpr_unsetenv("STS_CREDENTIALS"); } -typedef class ::grpc_impl::experimental::TlsKeyMaterialsConfig - TlsKeyMaterialsConfig; +typedef class ::grpc::experimental::TlsKeyMaterialsConfig TlsKeyMaterialsConfig; TEST_F(CredentialsTest, TlsKeyMaterialsConfigCppToC) { std::shared_ptr config(new TlsKeyMaterialsConfig()); @@ -304,9 +302,9 @@ TEST_F(CredentialsTest, TlsKeyMaterialsModifiers) { EXPECT_STREQ(list[0].cert_chain.c_str(), "cert_chain"); } -typedef class ::grpc_impl::experimental::TlsCredentialReloadArg +typedef class ::grpc::experimental::TlsCredentialReloadArg TlsCredentialReloadArg; -typedef class ::grpc_impl::experimental::TlsCredentialReloadConfig +typedef class ::grpc::experimental::TlsCredentialReloadConfig TlsCredentialReloadConfig; TEST_F(CredentialsTest, TlsCredentialReloadArgCallback) { @@ -433,9 +431,9 @@ TEST_F(CredentialsTest, TlsCredentialReloadConfigCppToC) { delete config.c_config(); } -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckArg +typedef class ::grpc::experimental::TlsServerAuthorizationCheckArg TlsServerAuthorizationCheckArg; -typedef class ::grpc_impl::experimental::TlsServerAuthorizationCheckConfig +typedef class ::grpc::experimental::TlsServerAuthorizationCheckConfig TlsServerAuthorizationCheckConfig; TEST_F(CredentialsTest, TlsServerAuthorizationCheckArgCallback) { @@ -550,8 +548,7 @@ TEST_F(CredentialsTest, TlsServerAuthorizationCheckConfigCppToC) { delete config.c_config(); } -typedef class ::grpc_impl::experimental::TlsCredentialsOptions - TlsCredentialsOptions; +typedef class ::grpc::experimental::TlsCredentialsOptions TlsCredentialsOptions; TEST_F(CredentialsTest, TlsCredentialsOptionsCppToC) { std::shared_ptr key_materials_config( @@ -681,7 +678,7 @@ TEST_F(CredentialsTest, LoadTlsChannelCredentials) { TlsCredentialsOptions options = TlsCredentialsOptions( GRPC_TLS_SERVER_VERIFICATION, nullptr, credential_reload_config, server_authorization_check_config); - std::shared_ptr channel_credentials = + std::shared_ptr channel_credentials = grpc::experimental::TlsCredentials(options); GPR_ASSERT(channel_credentials.get() != nullptr); } diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 3ce6109b49d..a4080632735 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -940,7 +940,6 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ -include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -1024,7 +1023,6 @@ include/grpcpp/resource_quota.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ -include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 2dd2cb0c123..bcb79a23158 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -940,7 +940,6 @@ include/grpcpp/client_context.h \ include/grpcpp/completion_queue.h \ include/grpcpp/completion_queue_impl.h \ include/grpcpp/create_channel.h \ -include/grpcpp/create_channel_impl.h \ include/grpcpp/create_channel_posix.h \ include/grpcpp/ext/health_check_service_server_builder_option.h \ include/grpcpp/generic/async_generic_service.h \ @@ -1024,7 +1023,6 @@ include/grpcpp/resource_quota.h \ include/grpcpp/security/auth_context.h \ include/grpcpp/security/auth_metadata_processor.h \ include/grpcpp/security/credentials.h \ -include/grpcpp/security/credentials_impl.h \ include/grpcpp/security/server_credentials.h \ include/grpcpp/security/server_credentials_impl.h \ include/grpcpp/security/tls_credentials_options.h \ From da9b03638a98e25a5e2bc5a49072ac52f9e33f29 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 24 Jul 2020 14:03:48 -0700 Subject: [PATCH 26/45] Fix BUILD file for import. --- src/proto/grpc/testing/xds/v3/BUILD | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/proto/grpc/testing/xds/v3/BUILD b/src/proto/grpc/testing/xds/v3/BUILD index 29053bf93eb..2631c5866b5 100644 --- a/src/proto/grpc/testing/xds/v3/BUILD +++ b/src/proto/grpc/testing/xds/v3/BUILD @@ -42,7 +42,7 @@ grpc_proto_library( ], well_known_protos = True, deps = [ - ":percent_proto", + "percent_proto", ], ) @@ -61,8 +61,8 @@ grpc_proto_library( ], well_known_protos = True, deps = [ - ":base_proto", - ":status_proto", + "base_proto", + "status_proto", ], ) @@ -74,7 +74,7 @@ grpc_proto_library( has_services = True, well_known_protos = True, deps = [ - ":discovery_proto", + "discovery_proto", ], ) @@ -91,7 +91,7 @@ grpc_proto_library( "cluster.proto", ], deps = [ - ":config_source_proto", + "config_source_proto", ], ) @@ -102,9 +102,9 @@ grpc_proto_library( ], well_known_protos = True, deps = [ - ":address_proto", - ":base_proto", - ":percent_proto", + "address_proto", + "base_proto", + "percent_proto", ], ) @@ -123,8 +123,8 @@ grpc_proto_library( ], well_known_protos = True, deps = [ - ":address_proto", - ":base_proto", + "address_proto", + "base_proto", ], ) @@ -136,8 +136,8 @@ grpc_proto_library( has_services = True, well_known_protos = True, deps = [ - ":base_proto", - ":load_report_proto", + "base_proto", + "load_report_proto", ], ) @@ -169,10 +169,10 @@ grpc_proto_library( ], well_known_protos = True, deps = [ - ":base_proto", - ":percent_proto", - ":range_proto", - ":regex_proto", + "base_proto", + "percent_proto", + "range_proto", + "regex_proto", ], ) @@ -182,7 +182,7 @@ grpc_proto_library( "http_connection_manager.proto", ], deps = [ - ":config_source_proto", - ":route_proto", + "config_source_proto", + "route_proto", ], ) From 6fc2e798e63a2215f0a13f46a20d76e3592b7717 Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Fri, 24 Jul 2020 14:51:07 -0700 Subject: [PATCH 27/45] Member variable should not be a reference; causing crash when used in destructor. --- .../lb_policy/weighted_target/weighted_target.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc index 83bc6cc9a54..c1baca11258 100644 --- a/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +++ b/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc @@ -171,7 +171,7 @@ class WeightedTargetLb : public LoadBalancingPolicy { // The owning LB policy. RefCountedPtr weighted_target_policy_; - const std::string& name_; + const std::string name_; uint32_t weight_; @@ -290,9 +290,8 @@ void WeightedTargetLb::UpdateLocked(UpdateArgs args) { const std::string& name = p.first; auto it = targets_.find(name); if (it == targets_.end()) { - it = targets_.emplace(std::make_pair(name, nullptr)).first; - it->second = MakeOrphanable( - Ref(DEBUG_LOCATION, "WeightedChild"), it->first); + targets_.emplace(name, MakeOrphanable( + Ref(DEBUG_LOCATION, "WeightedChild"), name)); } } // Update all children. From 2fc3131829d2ada69baf53a570e3cf3a4df50f08 Mon Sep 17 00:00:00 2001 From: daicoden Date: Fri, 24 Jul 2020 15:52:56 -1000 Subject: [PATCH 28/45] Add copyrights --- .../namespaced/upper/example/BUILD | 16 ++++++++++++++++ .../upper/example/import_no_strip_test.py | 14 ++++++++++++++ .../upper/example/import_strip_test.py | 14 ++++++++++++++ .../upper/example/no_import_no_strip_test.py | 14 ++++++++++++++ .../upper/example/no_import_strip_test.py | 14 ++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/bazel/test/python_test_repo/namespaced/upper/example/BUILD b/bazel/test/python_test_repo/namespaced/upper/example/BUILD index 9265b94d49b..8995a73159a 100644 --- a/bazel/test/python_test_repo/namespaced/upper/example/BUILD +++ b/bazel/test/python_test_repo/namespaced/upper/example/BUILD @@ -1,3 +1,19 @@ +# gRPC Bazel BUILD file. +# +# Copyright 2020 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. + load("@rules_proto//proto:defs.bzl", "proto_library") load( "@com_github_grpc_grpc//bazel:python_rules.bzl", diff --git a/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py index f22090f5533..1b5505dfc73 100644 --- a/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py +++ b/bazel/test/python_test_repo/namespaced/upper/example/import_no_strip_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + import logging import unittest diff --git a/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py index 0c5ae8b5c11..3519a8aa470 100644 --- a/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py +++ b/bazel/test/python_test_repo/namespaced/upper/example/import_strip_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + import logging import unittest diff --git a/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py index 1c3d0acd888..c08681758e5 100644 --- a/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py +++ b/bazel/test/python_test_repo/namespaced/upper/example/no_import_no_strip_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + import logging import unittest diff --git a/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py b/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py index 74638afb374..38dd4fba247 100644 --- a/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py +++ b/bazel/test/python_test_repo/namespaced/upper/example/no_import_strip_test.py @@ -1,3 +1,17 @@ +# Copyright 2020 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. + import logging import unittest From 70a6e7c644316a856bd006b9f85f41bfd3651a24 Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Sun, 26 Jul 2020 22:48:17 -0700 Subject: [PATCH 29/45] Passing repo manager to markdroth --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/cleanup_request.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/ISSUE_TEMPLATE/question.md | 2 +- .github/pull_request_template.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 1a096d52749..41f81be1db6 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: donnadionne +assignees: markdroth --- diff --git a/.github/ISSUE_TEMPLATE/cleanup_request.md b/.github/ISSUE_TEMPLATE/cleanup_request.md index ef88ef49ac5..7da478019fc 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, priority/P2 -assignees: donnadionne +assignees: markdroth --- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index f230fe25a3a..00599d145d8 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, priority/P2 -assignees: donnadionne +assignees: markdroth --- diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md index 77ecf5ea984..5dc067381f9 100644 --- a/.github/ISSUE_TEMPLATE/question.md +++ b/.github/ISSUE_TEMPLATE/question.md @@ -2,7 +2,7 @@ name: Ask a question about: Ask a question labels: kind/question, priority/P3 -assignees: donnadionne +assignees: markdroth --- diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index eddba6676da..a85cfad9c7a 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 --> -@donnadionne +@markdroth From 59da17dd7d3a268110287fb26eb4f55182d55bbb Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Sun, 26 Jul 2020 23:10:18 -0700 Subject: [PATCH 30/45] Fix parent/child process synchronization in two ruby tests --- ...ta_doesnt_kill_background_thread_driver.rb | 9 ---- .../call_credentials_timeout_driver.rb | 9 ---- src/ruby/end2end/channel_closing_driver.rb | 13 +++++- src/ruby/end2end/end2end_common.rb | 35 ++++++++++++++++ .../end2end/graceful_sig_handling_driver.rb | 41 +++---------------- src/ruby/end2end/graceful_sig_stop_driver.rb | 37 +++-------------- src/ruby/end2end/sig_handling_driver.rb | 38 +++-------------- .../sig_int_during_channel_watch_client.rb | 10 +++++ .../sig_int_during_channel_watch_driver.rb | 9 ++-- 9 files changed, 77 insertions(+), 124 deletions(-) diff --git a/src/ruby/end2end/call_credentials_returning_bad_metadata_doesnt_kill_background_thread_driver.rb b/src/ruby/end2end/call_credentials_returning_bad_metadata_doesnt_kill_background_thread_driver.rb index 414e97522ca..5ff9405a653 100755 --- a/src/ruby/end2end/call_credentials_returning_bad_metadata_doesnt_kill_background_thread_driver.rb +++ b/src/ruby/end2end/call_credentials_returning_bad_metadata_doesnt_kill_background_thread_driver.rb @@ -49,15 +49,6 @@ def create_server_creds true) # force client auth end -# Useful to update a value within a do block -class MutableValue - attr_accessor :value - - def initialize(value) - @value = value - end -end - def run_rpc_expect_unavailable(stub) exception = nil begin diff --git a/src/ruby/end2end/call_credentials_timeout_driver.rb b/src/ruby/end2end/call_credentials_timeout_driver.rb index 7618b14b974..233a0c4f071 100755 --- a/src/ruby/end2end/call_credentials_timeout_driver.rb +++ b/src/ruby/end2end/call_credentials_timeout_driver.rb @@ -49,15 +49,6 @@ def create_server_creds true) # force client auth end -# Useful to update a value within a do block -class MutableValue - attr_accessor :value - - def initialize(value) - @value = value - end -end - # rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/MethodLength def main diff --git a/src/ruby/end2end/channel_closing_driver.rb b/src/ruby/end2end/channel_closing_driver.rb index 8b91b93362b..10c7d7fca02 100755 --- a/src/ruby/end2end/channel_closing_driver.rb +++ b/src/ruby/end2end/channel_closing_driver.rb @@ -31,8 +31,17 @@ def main sleep 3 begin - Timeout.timeout(10) do - control_stub.shutdown(ClientControl::Void.new) + Timeout.timeout(20) do + loop do + begin + control_stub.shutdown(ClientControl::Void.new) + break + rescue GRPC::BadStatus => e + STDERR.puts "control_stub.shutdown RPC received error:|#{e}|. " \ + "This could mean that that child process e.g. isn't running yet, " \ + "so we'll retry the RPC" + end + end Process.wait(client_pid) end rescue Timeout::Error diff --git a/src/ruby/end2end/end2end_common.rb b/src/ruby/end2end/end2end_common.rb index 1bc17066735..7c8dea0f742 100755 --- a/src/ruby/end2end/end2end_common.rb +++ b/src/ruby/end2end/end2end_common.rb @@ -33,12 +33,47 @@ require_relative '../spec/support/helpers' include GRPC::Spec::Helpers +# Useful to update a value within a do block +class MutableValue + attr_accessor :value + + def initialize(value) + @value = value + end +end + # GreeterServer is simple server that implements the Helloworld Greeter server. +# This service also has a mechanism to wait for a timeout until the first +# RPC has been received, which is useful for synchronizing between parent +# and child processes. class EchoServerImpl < Echo::EchoServer::Service + def initialize + @first_rpc_received_mu = Mutex.new + @first_rpc_received_cv = ConditionVariable.new + @first_rpc_received = MutableValue.new(false) + end + # say_hello implements the SayHello rpc method. def echo(echo_req, _) + @first_rpc_received_mu.synchronize do + @first_rpc_received.value = true + @first_rpc_received_cv.broadcast + end Echo::EchoReply.new(response: echo_req.request) end + + def wait_for_first_rpc_received(timeout_seconds) + Timeout.timeout(timeout_seconds) do + @first_rpc_received_mu.synchronize do + until @first_rpc_received.value + @first_rpc_received_cv.wait(@first_rpc_received_mu) + end + end + end + rescue => e + fail "Received error:|#{e}| while waiting for #{timeout_seconds} " \ + 'seconds to receive the first RPC' + end end # ServerRunner starts an "echo server" that test clients can make calls to diff --git a/src/ruby/end2end/graceful_sig_handling_driver.rb b/src/ruby/end2end/graceful_sig_handling_driver.rb index e12ae284858..1a4d0d80d91 100755 --- a/src/ruby/end2end/graceful_sig_handling_driver.rb +++ b/src/ruby/end2end/graceful_sig_handling_driver.rb @@ -19,51 +19,23 @@ require_relative './end2end_common' -# A service that calls back it's received_rpc_callback -# upon receiving an RPC. Used for synchronization/waiting -# for child process to start. -class ClientStartedService < Echo::EchoServer::Service - def initialize(received_rpc_callback) - @received_rpc_callback = received_rpc_callback - end - - def echo(echo_req, _) - @received_rpc_callback.call unless @received_rpc_callback.nil? - @received_rpc_callback = nil - Echo::EchoReply.new(response: echo_req.request) - end -end - def main STDERR.puts 'start server' - client_started = false - client_started_mu = Mutex.new - client_started_cv = ConditionVariable.new - received_rpc_callback = proc do - client_started_mu.synchronize do - client_started = true - client_started_cv.signal - end - end - - client_started_service = ClientStartedService.new(received_rpc_callback) - server_runner = ServerRunner.new(client_started_service) + echo_service = EchoServerImpl.new + server_runner = ServerRunner.new(echo_service) server_port = server_runner.run STDERR.puts 'start client' control_stub, client_pid = start_client('graceful_sig_handling_client.rb', server_port) - - client_started_mu.synchronize do - client_started_cv.wait(client_started_mu) until client_started - end - + # use receipt of one RPC to indicate that the child process is + # ready + echo_service.wait_for_first_rpc_received(20) + # now get the client to send an RPC control_stub.do_echo_rpc( ClientControl::DoEchoRpcRequest.new(request: 'hello')) - STDERR.puts 'killing client' Process.kill('SIGINT', client_pid) Process.wait(client_pid) client_exit_status = $CHILD_STATUS - if client_exit_status.exited? if client_exit_status.exitstatus != 0 STDERR.puts 'Client did not close gracefully' @@ -75,7 +47,6 @@ def main end STDERR.puts 'Client ended gracefully' - # no need to call cleanup, client should already be dead server_runner.stop end diff --git a/src/ruby/end2end/graceful_sig_stop_driver.rb b/src/ruby/end2end/graceful_sig_stop_driver.rb index 7a132403ebf..3c1e3cde9d6 100755 --- a/src/ruby/end2end/graceful_sig_stop_driver.rb +++ b/src/ruby/end2end/graceful_sig_stop_driver.rb @@ -19,43 +19,16 @@ require_relative './end2end_common' -# A service that calls back it's received_rpc_callback -# upon receiving an RPC. Used for synchronization/waiting -# for child process to start. -class ClientStartedService < Echo::EchoServer::Service - def initialize(received_rpc_callback) - @received_rpc_callback = received_rpc_callback - end - - def echo(echo_req, _) - @received_rpc_callback.call unless @received_rpc_callback.nil? - @received_rpc_callback = nil - Echo::EchoReply.new(response: echo_req.request) - end -end - def main STDERR.puts 'start server' - client_started = false - client_started_mu = Mutex.new - client_started_cv = ConditionVariable.new - received_rpc_callback = proc do - client_started_mu.synchronize do - client_started = true - client_started_cv.signal - end - end - - client_started_service = ClientStartedService.new(received_rpc_callback) - server_runner = ServerRunner.new(client_started_service) + echo_service = EchoServerImpl.new + server_runner = ServerRunner.new(echo_service) server_port = server_runner.run STDERR.puts 'start client' control_stub, client_pid = start_client('./graceful_sig_stop_client.rb', server_port) - - client_started_mu.synchronize do - client_started_cv.wait(client_started_mu) until client_started - end - + # use receipt of one RPC to indicate that the child process is + # ready + echo_service.wait_for_first_rpc_received(20) cleanup(control_stub, client_pid, server_runner) end diff --git a/src/ruby/end2end/sig_handling_driver.rb b/src/ruby/end2end/sig_handling_driver.rb index 0ad1cbd661d..8a8a4426f6f 100755 --- a/src/ruby/end2end/sig_handling_driver.rb +++ b/src/ruby/end2end/sig_handling_driver.rb @@ -19,43 +19,16 @@ require_relative './end2end_common' -# A service that calls back it's received_rpc_callback -# upon receiving an RPC. Used for synchronization/waiting -# for child process to start. -class ClientStartedService < Echo::EchoServer::Service - def initialize(received_rpc_callback) - @received_rpc_callback = received_rpc_callback - end - - def echo(echo_req, _) - @received_rpc_callback.call unless @received_rpc_callback.nil? - @received_rpc_callback = nil - Echo::EchoReply.new(response: echo_req.request) - end -end - def main STDERR.puts 'start server' - client_started = false - client_started_mu = Mutex.new - client_started_cv = ConditionVariable.new - received_rpc_callback = proc do - client_started_mu.synchronize do - client_started = true - client_started_cv.signal - end - end - - client_started_service = ClientStartedService.new(received_rpc_callback) - server_runner = ServerRunner.new(client_started_service) + echo_service = EchoServerImpl.new + server_runner = ServerRunner.new(echo_service) server_port = server_runner.run STDERR.puts 'start client' control_stub, client_pid = start_client('sig_handling_client.rb', server_port) - - client_started_mu.synchronize do - client_started_cv.wait(client_started_mu) until client_started - end - + # use receipt of one RPC to indicate that the child process is + # ready + echo_service.wait_for_first_rpc_received(20) count = 0 while count < 5 control_stub.do_echo_rpc( @@ -64,7 +37,6 @@ def main Process.kill('SIGINT', client_pid) count += 1 end - cleanup(control_stub, client_pid, server_runner) end diff --git a/src/ruby/end2end/sig_int_during_channel_watch_client.rb b/src/ruby/end2end/sig_int_during_channel_watch_client.rb index fb930f887de..9cdeac7329f 100755 --- a/src/ruby/end2end/sig_int_during_channel_watch_client.rb +++ b/src/ruby/end2end/sig_int_during_channel_watch_client.rb @@ -34,6 +34,16 @@ def main trap('SIGINT') { exit 0 } STDERR.puts 'sig_int_during_channel_watch_client.rb: SIGINT trap has been set' + # First, notify the parent process that we're ready for a SIGINT by sending + # an RPC + begin + stub = Echo::EchoServer::Stub.new( + "localhost:#{server_port}", :this_channel_is_insecure) + stub.echo(ClientControl::DoEchoRpcRequest.new) + rescue => e + fail "received error:|#{e}| while sending an RPC to the parent process " \ + 'to indicate that the SIGINT trap has been set' + end thd = Thread.new do child_thread_channel = GRPC::Core::Channel.new("localhost:#{server_port}", diff --git a/src/ruby/end2end/sig_int_during_channel_watch_driver.rb b/src/ruby/end2end/sig_int_during_channel_watch_driver.rb index 2df22f48a2e..8a4ab5100ab 100755 --- a/src/ruby/end2end/sig_int_during_channel_watch_driver.rb +++ b/src/ruby/end2end/sig_int_during_channel_watch_driver.rb @@ -21,16 +21,19 @@ require_relative './end2end_common' def main STDERR.puts 'start server' - server_runner = ServerRunner.new(EchoServerImpl) + echo_service = EchoServerImpl.new + server_runner = ServerRunner.new(echo_service) server_port = server_runner.run STDERR.puts 'start client' _, client_pid = start_client('sig_int_during_channel_watch_client.rb', server_port) + # use receipt of one RPC to indicate that the child process is + # ready for a SIGINT + echo_service.wait_for_first_rpc_received(20) # give time for the client to get into the middle # of a channel state watch call sleep 1 Process.kill('SIGINT', client_pid) - begin Timeout.timeout(10) do Process.wait(client_pid) @@ -43,12 +46,10 @@ def main raise 'Timed out waiting for client process. It likely hangs when a ' \ 'SIGINT is sent while there is an active connectivity_state call' end - client_exit_code = $CHILD_STATUS if client_exit_code != 0 fail "sig_int_during_channel_watch_client failed: #{client_exit_code}" end - server_runner.stop end From 8b3224ba621e85f56c6d739c877f0949a5466b45 Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Mon, 27 Jul 2020 09:37:39 -0700 Subject: [PATCH 31/45] Fixing a member var to not be a reference. --- .../filters/client_channel/lb_policy/xds/xds_routing.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc index a3672e14bce..aba1d6cfba5 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds_routing.cc @@ -187,7 +187,7 @@ class XdsRoutingLb : public LoadBalancingPolicy { RefCountedPtr xds_routing_policy_; // Points to the corresponding key in XdsRoutingLb::actions_. - const std::string& name_; + const std::string name_; OrphanablePtr child_policy_; @@ -407,9 +407,10 @@ void XdsRoutingLb::UpdateLocked(UpdateArgs args) { const RefCountedPtr& config = p.second; auto it = actions_.find(name); if (it == actions_.end()) { - it = actions_.emplace(std::make_pair(name, nullptr)).first; - it->second = MakeOrphanable( - Ref(DEBUG_LOCATION, "XdsRoutingChild"), it->first); + it = actions_ + .emplace(name, MakeOrphanable( + Ref(DEBUG_LOCATION, "XdsRoutingChild"), name)) + .first; } it->second->UpdateLocked(config, args.addresses, args.args); } From 1c2f57ae1dd54ee94cc3b53c9683b7b392f645a9 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Wed, 8 Jul 2020 15:11:16 -0700 Subject: [PATCH 32/45] xds interop: add routing path matching to framework - prefix and full path - header matching - print client cmd to run - new test cases are not included in all --- tools/run_tests/run_xds_tests.py | 289 ++++++++++++++++++++++++++++--- 1 file changed, 263 insertions(+), 26 deletions(-) diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 3073d301ded..5f6ffd431f0 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -56,17 +56,28 @@ _TEST_CASES = [ 'secondary_locality_gets_requests_on_primary_failure', 'traffic_splitting', ] +# Valid test cases, but not in all. So the tests can only run manually, and +# aren't enabled automatically for all languages. +# +# TODO: Move them into _TEST_CASES when support is ready in all languages. +_ADDITIONAL_TEST_CASES = ['path_matching', 'header_matching'] def parse_test_cases(arg): - if arg == 'all': - return _TEST_CASES if arg == '': return [] - test_cases = arg.split(',') - if all([test_case in _TEST_CASES for test_case in test_cases]): - return test_cases - raise Exception('Failed to parse test cases %s' % arg) + arg_split = arg.split(',') + test_cases = set() + all_test_cases = _TEST_CASES + _ADDITIONAL_TEST_CASES + for arg in arg_split: + if arg == "all": + test_cases = test_cases.union(_TEST_CASES) + else: + test_cases = test_cases.union([arg]) + if not all([test_case in all_test_cases for test_case in test_cases]): + raise Exception('Failed to parse test cases %s' % arg) + # Perserve order. + return [x for x in all_test_cases if x in test_cases] def parse_port_range(port_arg): @@ -89,8 +100,10 @@ argp.add_argument( '--test_case', default='ping_pong', type=parse_test_cases, - help='Comma-separated list of test cases to run, or \'all\' to run every ' - 'test. Available tests: %s' % ' '.join(_TEST_CASES)) + help='Comma-separated list of test cases to run. Available tests: %s, ' + '(or \'all\' to run every test). ' + 'Alternative tests not included in \'all\': %s' % + (','.join(_TEST_CASES), ','.join(_ADDITIONAL_TEST_CASES))) argp.add_argument( '--bootstrap_file', default='', @@ -237,6 +250,12 @@ _BOOTSTRAP_TEMPLATE = """ _TESTS_TO_FAIL_ON_RPC_FAILURE = [ 'new_instance_group_receives_traffic', 'ping_pong', 'round_robin' ] +# Tests that run UnaryCall and EmptyCall. +_TESTS_TO_RUN_MULTIPLE_RPCS = ['path_matching', 'header_matching'] +# Tests that make UnaryCall with test metadata. +_TESTS_TO_SEND_METADATA = ['header_matching'] +_TEST_METADATA_KEY = 'xds_md' +_TEST_METADATA_VALUE = 'exact_match' _PATH_MATCHER_NAME = 'path-matcher' _BASE_TEMPLATE_NAME = 'test-template' _BASE_INSTANCE_GROUP_NAME = 'test-ig' @@ -348,6 +367,29 @@ def compare_distributions(actual_distribution, expected_distribution, return True +def compare_expected_instances(stats, expected_instances): + """Compare if stats have expected instances for each type of RPC. + + Args: + stats: LoadBalancerStatsResponse reported by interop client. + expected_instances: a dict with key as the RPC type (string), value as + the expected backend instances (list of strings). + + Returns: + Returns true if the instances are expected. False if not. + """ + for rpc_type, expected_peers in expected_instances.items(): + rpcs_by_peer_for_type = stats.rpcs_by_method[rpc_type] + rpcs_by_peer = rpcs_by_peer_for_type.rpcs_by_peer if rpcs_by_peer_for_type else None + logger.debug('rpc: %s, by_peer: %s', rpc_type, rpcs_by_peer) + peers = list(rpcs_by_peer.keys()) + if set(peers) != set(expected_peers): + logger.info('unexpected peers for %s, got %s, want %s', rpc_type, + peers, expected_peers) + return False + return True + + def test_backends_restart(gcp, backend_service, instance_group): logger.info('Running test_backends_restart') instance_names = get_instance_names(gcp, instance_group) @@ -629,19 +671,20 @@ def test_secondary_locality_gets_requests_on_primary_failure( patch_backend_instances(gcp, backend_service, [primary_instance_group]) -def test_traffic_splitting(gcp, original_backend_service, instance_group, - alternate_backend_service, same_zone_instance_group): - # This test start with all traffic going to original_backend_service. Then - # it updates URL-map to set default action to traffic splitting between - # original and alternate. It waits for all backends in both services to - # receive traffic, then verifies that weights are expected. - logger.info('Running test_traffic_splitting') +def prepare_services_for_urlmap_tests(gcp, original_backend_service, + instance_group, alternate_backend_service, + same_zone_instance_group): + ''' + This function prepares the services to be ready for tests that modifies + urlmaps. + Returns: + Returns original and alternate backend names as lists of strings. + ''' # The config validation for proxyless doesn't allow setting - # default_route_action. To test traffic splitting, we need to set the - # route action to weighted clusters. Disable validate - # validate_for_proxyless for this test. This can be removed when - # validation accepts default_route_action. + # default_route_action or route_rules. Disable validate + # validate_for_proxyless for this test. This can be removed when validation + # accepts default_route_action. logger.info('disabling validate_for_proxyless in target proxy') set_validate_for_proxyless(gcp, False) @@ -665,6 +708,20 @@ def test_traffic_splitting(gcp, original_backend_service, instance_group, logger.info('waiting for traffic to all go to original backends') wait_until_all_rpcs_go_to_given_backends(original_backend_instances, _WAIT_FOR_STATS_SEC) + return original_backend_instances, alternate_backend_instances + + +def test_traffic_splitting(gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group): + # This test start with all traffic going to original_backend_service. Then + # it updates URL-map to set default action to traffic splitting between + # original and alternate. It waits for all backends in both services to + # receive traffic, then verifies that weights are expected. + logger.info('Running test_traffic_splitting') + + original_backend_instances, alternate_backend_instances = prepare_services_for_urlmap_tests( + gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group) try: # Patch urlmap, change route action to traffic splitting between @@ -728,6 +785,157 @@ def test_traffic_splitting(gcp, original_backend_service, instance_group, set_validate_for_proxyless(gcp, True) +def test_path_matching(gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group): + # This test start with all traffic (UnaryCall and EmptyCall) going to + # original_backend_service. + # + # Then it updates URL-map to add routes, to make UnaryCall and EmptyCall to + # go different backends. It waits for all backends in both services to + # receive traffic, then verifies that traffic goes to the expected + # backends. + logger.info('Running test_path_matching') + + original_backend_instances, alternate_backend_instances = prepare_services_for_urlmap_tests( + gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group) + + try: + # A list of tuples (route_rules, expected_instances). + test_cases = [ + ( + [{ + 'priority': 0, + # FullPath EmptyCall -> alternate_backend_service. + 'matchRules': [{ + 'fullPathMatch': '/grpc.testing.TestService/EmptyCall' + }], + 'service': alternate_backend_service.url + }], + { + "EmptyCall": alternate_backend_instances, + "UnaryCall": original_backend_instances + }), + ( + [{ + 'priority': 0, + # Prefix UnaryCall -> alternate_backend_service. + 'matchRules': [{ + 'prefixMatch': '/grpc.testing.TestService/Unary' + }], + 'service': alternate_backend_service.url + }], + { + "UnaryCall": alternate_backend_instances, + "EmptyCall": original_backend_instances + }) + ] + + for (route_rules, expected_instances) in test_cases: + logger.info('patching url map with %s -> alternative', + route_rules[0]['matchRules']) + patch_url_map_backend_service(gcp, + original_backend_service, + route_rules=route_rules) + + # Wait for traffic to go to both services. + logger.info( + 'waiting for traffic to go to all backends (including alternate)' + ) + wait_until_all_rpcs_go_to_given_backends( + original_backend_instances + alternate_backend_instances, + _WAIT_FOR_STATS_SEC) + + retry_count = 10 + # Each attempt takes about 10 seconds, 10 retries is equivalent to 100 + # seconds timeout. + for i in range(retry_count): + stats = get_client_stats(_NUM_TEST_RPCS, _WAIT_FOR_STATS_SEC) + if not stats.rpcs_by_method: + raise ValueError( + 'stats.rpcs_by_method is None, the interop client stats service does not support this test case' + ) + logger.info('attempt %d', i) + if compare_expected_instances(stats, expected_instances): + logger.info("success") + break + finally: + patch_url_map_backend_service(gcp, original_backend_service) + patch_backend_instances(gcp, alternate_backend_service, []) + set_validate_for_proxyless(gcp, True) + + +def test_header_matching(gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group): + # This test start with all traffic (UnaryCall and EmptyCall) going to + # original_backend_service. + # + # Then it updates URL-map to add routes, to make RPCs with test headers to + # go to different backends. It waits for all backends in both services to + # receive traffic, then verifies that traffic goes to the expected + # backends. + logger.info('Running test_header_matching') + + original_backend_instances, alternate_backend_instances = prepare_services_for_urlmap_tests( + gcp, original_backend_service, instance_group, + alternate_backend_service, same_zone_instance_group) + + try: + # A list of tuples (route_rules, expected_instances). + test_cases = [( + [{ + 'priority': 0, + # Header ExactMatch -> alternate_backend_service. + # EmptyCall is sent with the metadata. + 'matchRules': [{ + 'prefixMatch': + '/', + 'headerMatches': [{ + 'headerName': _TEST_METADATA_KEY, + 'exactMatch': _TEST_METADATA_VALUE + }] + }], + 'service': alternate_backend_service.url + }], + { + "EmptyCall": alternate_backend_instances, + "UnaryCall": original_backend_instances + })] + + for (route_rules, expected_instances) in test_cases: + logger.info('patching url map with %s -> alternative', + route_rules[0]['matchRules']) + patch_url_map_backend_service(gcp, + original_backend_service, + route_rules=route_rules) + + # Wait for traffic to go to both services. + logger.info( + 'waiting for traffic to go to all backends (including alternate)' + ) + wait_until_all_rpcs_go_to_given_backends( + original_backend_instances + alternate_backend_instances, + _WAIT_FOR_STATS_SEC) + + retry_count = 10 + # Each attempt takes about 10 seconds, 10 retries is equivalent to 100 + # seconds timeout. + for i in range(retry_count): + stats = get_client_stats(_NUM_TEST_RPCS, _WAIT_FOR_STATS_SEC) + if not stats.rpcs_by_method: + raise ValueError( + 'stats.rpcs_by_method is None, the interop client stats service does not support this test case' + ) + logger.info('attempt %d', i) + if compare_expected_instances(stats, expected_instances): + logger.info("success") + break + finally: + patch_url_map_backend_service(gcp, original_backend_service) + patch_backend_instances(gcp, alternate_backend_service, []) + set_validate_for_proxyless(gcp, True) + + def set_serving_status(instances, service_port, serving): for instance in instances: with grpc.insecure_channel('%s:%d' % @@ -1208,7 +1416,8 @@ def resize_instance_group(gcp, def patch_url_map_backend_service(gcp, backend_service=None, - services_with_weights=None): + services_with_weights=None, + route_rules=None): '''change url_map's backend service Only one of backend_service and service_with_weights can be not None. @@ -1230,6 +1439,7 @@ def patch_url_map_backend_service(gcp, 'name': _PATH_MATCHER_NAME, 'defaultService': default_service, 'defaultRouteAction': default_route_action, + 'routeRules': route_rules, }] } logger.debug('Sending GCP request with body=%s', config) @@ -1504,22 +1714,41 @@ try: test_log_filename = os.path.join(log_dir, _SPONGE_LOG_NAME) test_log_file = open(test_log_filename, 'w+') client_process = None + + if test_case in _TESTS_TO_RUN_MULTIPLE_RPCS: + rpcs_to_send = '--rpc="UnaryCall,EmptyCall"' + else: + rpcs_to_send = '--rpc="UnaryCall"' + + if test_case in _TESTS_TO_SEND_METADATA: + metadata_to_send = '--metadata="EmptyCall:{key}:{value}"'.format( + key=_TEST_METADATA_KEY, value=_TEST_METADATA_VALUE) + else: + metadata_to_send = '--metadata=""' + if test_case in _TESTS_TO_FAIL_ON_RPC_FAILURE: wait_for_config_propagation( gcp, instance_group, args.client_cmd.format(server_uri=server_uri, stats_port=args.stats_port, qps=args.qps, - fail_on_failed_rpc=False), + fail_on_failed_rpc=False, + rpcs_to_send=rpcs_to_send, + metadata_to_send=metadata_to_send), client_env) fail_on_failed_rpc = '--fail_on_failed_rpc=true' else: fail_on_failed_rpc = '--fail_on_failed_rpc=false' - client_cmd = shlex.split( - args.client_cmd.format(server_uri=server_uri, - stats_port=args.stats_port, - qps=args.qps, - fail_on_failed_rpc=fail_on_failed_rpc)) + + client_cmd_formatted = args.client_cmd.format( + server_uri=server_uri, + stats_port=args.stats_port, + qps=args.qps, + fail_on_failed_rpc=fail_on_failed_rpc, + rpcs_to_send=rpcs_to_send, + metadata_to_send=metadata_to_send) + logger.debug('running client: %s', client_cmd_formatted) + client_cmd = shlex.split(client_cmd_formatted) try: client_process = subprocess.Popen(client_cmd, env=client_env, @@ -1559,6 +1788,14 @@ try: test_traffic_splitting(gcp, backend_service, instance_group, alternate_backend_service, same_zone_instance_group) + elif test_case == 'path_matching': + test_path_matching(gcp, backend_service, instance_group, + alternate_backend_service, + same_zone_instance_group) + elif test_case == 'header_matching': + test_header_matching(gcp, backend_service, instance_group, + alternate_backend_service, + same_zone_instance_group) else: logger.error('Unknown test case: %s', test_case) sys.exit(1) From 7df3017c8aec87167f3aff6004829a29be41401e Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Mon, 27 Jul 2020 10:05:11 -0700 Subject: [PATCH 33/45] Update semantics of --fail_on_failed_rpc --- doc/xds-test-descriptions.md | 4 +++- test/cpp/interop/xds_interop_client.cc | 9 +++++++-- tools/run_tests/run_xds_tests.py | 16 ---------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/doc/xds-test-descriptions.md b/doc/xds-test-descriptions.md index bd94bb4ce8d..c42583b2010 100644 --- a/doc/xds-test-descriptions.md +++ b/doc/xds-test-descriptions.md @@ -27,7 +27,9 @@ Clients should accept these arguments: * --fail_on_failed_rpcs=BOOL * If true, the client should exit with a non-zero return code if any RPCs - fail. Default is false. + fail after at least one RPC has succeeded, indicating a valid xDS config + was received. This accounts for any startup-related delays in receiving + an initial config from the load balancer. Default is false. * --num_channels=CHANNELS * The number of channels to create to the server. * --qps=QPS diff --git a/test/cpp/interop/xds_interop_client.cc b/test/cpp/interop/xds_interop_client.cc index 5d1b68dafd8..db36ff76344 100644 --- a/test/cpp/interop/xds_interop_client.cc +++ b/test/cpp/interop/xds_interop_client.cc @@ -16,6 +16,7 @@ * */ +#include #include #include #include @@ -41,7 +42,8 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/test_config.h" -DEFINE_bool(fail_on_failed_rpc, false, "Fail client if any RPCs fail."); +DEFINE_bool(fail_on_failed_rpc, false, + "Fail client if any RPCs fail after first successful RPC."); DEFINE_int32(num_channels, 1, "Number of channels."); DEFINE_bool(print_response, false, "Write RPC response to stdout."); DEFINE_int32(qps, 1, "Qps per channel."); @@ -80,6 +82,8 @@ int global_request_id; std::set watchers; // Mutex for global_request_id and watchers std::mutex mu; +// Whether at least one RPC has succeeded, indicating xDS resolution completed. +std::atomic one_rpc_succeeded(false); /** Records the remote peer distribution for a given range of RPCs. */ class XdsStatsWatcher { @@ -223,7 +227,7 @@ class TestClient { std::cout << "RPC failed: " << call->status.error_code() << ": " << call->status.error_message() << std::endl; } - if (FLAGS_fail_on_failed_rpc) { + if (FLAGS_fail_on_failed_rpc && one_rpc_succeeded.load()) { abort(); } } else { @@ -239,6 +243,7 @@ class TestClient { std::cout << "Greeting: Hello world, this is " << hostname << ", from " << call->context.peer() << std::endl; } + one_rpc_succeeded = true; } delete call; diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 3073d301ded..6970da49b2f 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -1314,15 +1314,6 @@ def wait_for_healthy_backends(gcp, (timeout_sec, result)) -def wait_for_config_propagation(gcp, instance_group, client_cmd, client_env): - """Use client to verify config propagation from GCP->TD->client""" - instance_names = get_instance_names(gcp, instance_group) - client_process = subprocess.Popen(shlex.split(client_cmd), env=client_env) - wait_until_all_rpcs_go_to_given_backends(instance_names, - _WAIT_FOR_VALID_CONFIG_SEC) - client_process.terminate() - - def get_instance_names(gcp, instance_group): instance_names = [] result = gcp.compute.instanceGroups().listInstances( @@ -1505,13 +1496,6 @@ try: test_log_file = open(test_log_filename, 'w+') client_process = None if test_case in _TESTS_TO_FAIL_ON_RPC_FAILURE: - wait_for_config_propagation( - gcp, instance_group, - args.client_cmd.format(server_uri=server_uri, - stats_port=args.stats_port, - qps=args.qps, - fail_on_failed_rpc=False), - client_env) fail_on_failed_rpc = '--fail_on_failed_rpc=true' else: fail_on_failed_rpc = '--fail_on_failed_rpc=false' From cba97021a9e0bbb684a71e0039d99ddc32a51958 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Sat, 25 Jul 2020 23:43:05 -0700 Subject: [PATCH 34/45] Remove an invalid assumption from ruby call creds timeout test --- src/ruby/end2end/call_credentials_timeout_driver.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ruby/end2end/call_credentials_timeout_driver.rb b/src/ruby/end2end/call_credentials_timeout_driver.rb index 7618b14b974..52789c3bf30 100755 --- a/src/ruby/end2end/call_credentials_timeout_driver.rb +++ b/src/ruby/end2end/call_credentials_timeout_driver.rb @@ -136,10 +136,16 @@ def main STDERR.puts 'now perform another RPC and expect OK...' stub.echo(Echo::EchoRequest.new(request: 'hello'), deadline: Time.now + 10) jwt_aud_uri_extraction_success_count_mu.synchronize do - if jwt_aud_uri_extraction_success_count.value != 2003 + if jwt_aud_uri_extraction_success_count.value < 4 + fail "Expected auth metadata plugin callback to be ran with the jwt_aud_uri +parameter matching its expected value at least 4 times (at least 1 out of the 2000 +initial expected-to-timeout RPCs should have caused this by now, and all three of the +successful RPCs should have caused this). This test isn't doing what it's meant to do." + end + unless jwt_aud_uri_failure_values.empty? fail "Expected to get jwt_aud_uri:#{expected_jwt_aud_uri} passed to call creds -user callback 2003 times, but it was only passed to the call creds user callback -#{jwt_aud_uri_extraction_success_count.value} times. This suggests that either: +user callback every time that it was invoked, but it did not match the expected value +in #{jwt_aud_uri_failure_values.size} invocations. This suggests that either: a) the expected jwt_aud_uri value is incorrect b) there is some corruption of the jwt_aud_uri argument Here are are the values of the jwt_aud_uri parameter that were passed to the call From 4c6a6b5a528cc8b4fec0f10edd3ad7de13a3bac3 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Mon, 27 Jul 2020 12:03:50 -0700 Subject: [PATCH 35/45] Clean up transport tests --- test/core/transport/byte_stream_test.cc | 2 +- test/core/transport/connectivity_state_test.cc | 2 +- test/core/transport/static_metadata_test.cc | 2 +- test/core/transport/status_conversion_test.cc | 4 +--- test/core/transport/status_metadata_test.cc | 5 +++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/core/transport/byte_stream_test.cc b/test/core/transport/byte_stream_test.cc index 589247a5887..16294079832 100644 --- a/test/core/transport/byte_stream_test.cc +++ b/test/core/transport/byte_stream_test.cc @@ -246,8 +246,8 @@ TEST(CachingByteStream, SharedCache) { } // namespace grpc_core int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); grpc::testing::TestEnvironment env(argc, argv); + ::testing::InitGoogleTest(&argc, argv); grpc_init(); int retval = RUN_ALL_TESTS(); grpc_shutdown(); diff --git a/test/core/transport/connectivity_state_test.cc b/test/core/transport/connectivity_state_test.cc index e0bd8d02198..9caff9db9b8 100644 --- a/test/core/transport/connectivity_state_test.cc +++ b/test/core/transport/connectivity_state_test.cc @@ -233,8 +233,8 @@ TEST(StateTracker, DoNotNotifyShutdownAtDestructionIfAlreadyInShutdown) { } // namespace grpc_core int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); grpc::testing::TestEnvironment env(argc, argv); + ::testing::InitGoogleTest(&argc, argv); grpc_init(); grpc_core::testing::grpc_tracer_enable_flag( &grpc_core::grpc_connectivity_state_trace); diff --git a/test/core/transport/static_metadata_test.cc b/test/core/transport/static_metadata_test.cc index 834b570f27d..c0943905d60 100644 --- a/test/core/transport/static_metadata_test.cc +++ b/test/core/transport/static_metadata_test.cc @@ -42,9 +42,9 @@ TEST(StaticMetadataTest, ReadAllStaticElements) { } // namespace grpc_core int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); grpc_init(); - grpc::testing::TestEnvironment env(argc, argv); int retval = RUN_ALL_TESTS(); grpc_shutdown(); return retval; diff --git a/test/core/transport/status_conversion_test.cc b/test/core/transport/status_conversion_test.cc index b09358bd991..06deb1f8ccd 100644 --- a/test/core/transport/status_conversion_test.cc +++ b/test/core/transport/status_conversion_test.cc @@ -162,8 +162,6 @@ static void test_http2_status_to_grpc_status() { } int main(int argc, char** argv) { - int i; - grpc::testing::TestEnvironment env(argc, argv); grpc_init(); @@ -173,7 +171,7 @@ int main(int argc, char** argv) { test_http2_status_to_grpc_status(); /* check all status values can be converted */ - for (i = 0; i <= 999; i++) { + for (int i = 0; i <= 999; i++) { grpc_http2_status_to_grpc_status(i); } diff --git a/test/core/transport/status_metadata_test.cc b/test/core/transport/status_metadata_test.cc index d5723a4313f..d2e2631757d 100644 --- a/test/core/transport/status_metadata_test.cc +++ b/test/core/transport/status_metadata_test.cc @@ -17,11 +17,11 @@ */ #include "src/core/lib/transport/status_metadata.h" +#include "src/core/lib/transport/static_metadata.h" +#include "test/core/util/test_config.h" #include -#include "src/core/lib/transport/static_metadata.h" - namespace { TEST(GetStatusCodeFromMetadata, OK) { @@ -56,6 +56,7 @@ TEST(GetStatusCodeFromMetadata, Unparseable) { } // namespace int main(int argc, char** argv) { + grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); grpc_init(); int ret = RUN_ALL_TESTS(); From 255a468b44406085f717ef118e8473aacdf2339b Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 27 Jul 2020 12:27:32 -0700 Subject: [PATCH 36/45] Hacks to fix build problems on import. --- CMakeLists.txt | 7 -- Makefile | 27 +----- build_autogenerated.yaml | 1 - src/proto/grpc/testing/xds/v3/BUILD | 9 -- src/proto/grpc/testing/xds/v3/discovery.proto | 17 +++- src/proto/grpc/testing/xds/v3/status.proto | 89 ------------------- 6 files changed, 19 insertions(+), 131 deletions(-) delete mode 100644 src/proto/grpc/testing/xds/v3/status.proto diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b85e61f25a..0ec8476491a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -478,9 +478,6 @@ protobuf_generate_grpc_cpp( protobuf_generate_grpc_cpp( src/proto/grpc/testing/xds/v3/route.proto ) -protobuf_generate_grpc_cpp( - src/proto/grpc/testing/xds/v3/status.proto -) protobuf_generate_grpc_cpp( test/core/tsi/alts/fake_handshaker/handshaker.proto ) @@ -14916,10 +14913,6 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/route.pb.h ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/route.grpc.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/status.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/status.pb.h - ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/xds/v3/status.grpc.pb.h test/cpp/end2end/test_service_impl.cc test/cpp/end2end/xds_end2end_test.cc third_party/googletest/googletest/src/gtest-all.cc diff --git a/Makefile b/Makefile index 40e2642512c..91248fc8755 100644 --- a/Makefile +++ b/Makefile @@ -2977,12 +2977,12 @@ $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc: protoc_dep_error $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc: protoc_dep_error else -$(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc: src/proto/grpc/testing/xds/v3/discovery.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc +$(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc: src/proto/grpc/testing/xds/v3/discovery.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(E) "[PROTOC] Generating protobuf CC file from $<" $(Q) mkdir -p `dirname $@` $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< -$(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc: src/proto/grpc/testing/xds/v3/discovery.proto $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc +$(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc: src/proto/grpc/testing/xds/v3/discovery.proto $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" $(Q) mkdir -p `dirname $@` $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< @@ -3132,22 +3132,6 @@ $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc: src/proto/grpc/testing $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< endif -ifeq ($(NO_PROTOC),true) -$(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc: protoc_dep_error -$(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc: protoc_dep_error -else - -$(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc: src/proto/grpc/testing/xds/v3/status.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[PROTOC] Generating protobuf CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< - -$(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc: src/proto/grpc/testing/xds/v3/status.proto $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) - $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" - $(Q) mkdir -p `dirname $@` - $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< -endif - ifeq ($(NO_PROTOC),true) $(GENDIR)/test/core/tsi/alts/fake_handshaker/handshaker.pb.cc: protoc_dep_error $(GENDIR)/test/core/tsi/alts/fake_handshaker/handshaker.grpc.pb.cc: protoc_dep_error @@ -19125,7 +19109,6 @@ XDS_END2END_TEST_SRC = \ $(GENDIR)/src/proto/grpc/testing/xds/v3/range.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/xds/v3/route.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc \ - $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc \ test/cpp/end2end/test_service_impl.cc \ test/cpp/end2end/xds_end2end_test.cc \ @@ -19206,8 +19189,6 @@ $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/xds/v3/regex.o: $(LIBDIR)/$(CONFIG)/ $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/xds/v3/route.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a -$(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/xds/v3/status.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a - $(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a $(OBJDIR)/$(CONFIG)/test/cpp/end2end/xds_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a @@ -19219,8 +19200,8 @@ ifneq ($(NO_DEPS),true) -include $(XDS_END2END_TEST_OBJS:.o=.dep) endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/xds_end2end_test.o: $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/status.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/test_service_impl.o: $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/xds_end2end_test.o: $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc $(GENDIR)/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.pb.cc $(GENDIR)/src/proto/grpc/testing/echo.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/echo_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.pb.cc $(GENDIR)/src/proto/grpc/testing/simple_messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/ads_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/cds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/eds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lds_rds_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/lrs_for_test.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/address.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/ads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/base.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/cluster.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/config_source.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/discovery.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/endpoint.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/http_connection_manager.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/listener.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/load_report.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/lrs.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/percent.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/range.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/regex.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.pb.cc $(GENDIR)/src/proto/grpc/testing/xds/v3/route.grpc.pb.cc XDS_INTEROP_CLIENT_SRC = \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 0737db79647..f5688a0cf32 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -7598,7 +7598,6 @@ targets: - src/proto/grpc/testing/xds/v3/range.proto - src/proto/grpc/testing/xds/v3/regex.proto - src/proto/grpc/testing/xds/v3/route.proto - - src/proto/grpc/testing/xds/v3/status.proto - test/cpp/end2end/test_service_impl.cc - test/cpp/end2end/xds_end2end_test.cc deps: diff --git a/src/proto/grpc/testing/xds/v3/BUILD b/src/proto/grpc/testing/xds/v3/BUILD index 2631c5866b5..aa2141e7eb6 100644 --- a/src/proto/grpc/testing/xds/v3/BUILD +++ b/src/proto/grpc/testing/xds/v3/BUILD @@ -46,14 +46,6 @@ grpc_proto_library( ], ) -grpc_proto_library( - name = "status_proto", - srcs = [ - "status.proto", - ], - well_known_protos = True, -) - grpc_proto_library( name = "discovery_proto", srcs = [ @@ -62,7 +54,6 @@ grpc_proto_library( well_known_protos = True, deps = [ "base_proto", - "status_proto", ], ) diff --git a/src/proto/grpc/testing/xds/v3/discovery.proto b/src/proto/grpc/testing/xds/v3/discovery.proto index 766ab8b2d82..2a697d9648f 100644 --- a/src/proto/grpc/testing/xds/v3/discovery.proto +++ b/src/proto/grpc/testing/xds/v3/discovery.proto @@ -21,7 +21,20 @@ package envoy.service.discovery.v3; import "src/proto/grpc/testing/xds/v3/base.proto"; import "google/protobuf/any.proto"; -import "src/proto/grpc/testing/xds/v3/status.proto"; + +message Status { + // The status code, which should be an enum value of [google.rpc.Code][]. + int32 code = 1; + + // A developer-facing error message, which should be in English. Any + // user-facing error message should be localized and sent in the + // [google.rpc.Status.details][] field, or localized by the client. + string message = 2; + + // A list of messages that carry the error details. There is a common set of + // message types for APIs to use. + repeated google.protobuf.Any details = 3; +} // [#protodoc-title: Common discovery API components] @@ -66,7 +79,7 @@ message DiscoveryRequest { // failed to update configuration. The *message* field in *error_details* provides the Envoy // internal exception related to the failure. It is only intended for consumption during manual // debugging, the string provided is not guaranteed to be stable across Envoy versions. - google.rpc.Status error_detail = 6; + Status error_detail = 6; } // [#next-free-field: 7] diff --git a/src/proto/grpc/testing/xds/v3/status.proto b/src/proto/grpc/testing/xds/v3/status.proto deleted file mode 100644 index 7c4602a3b33..00000000000 --- a/src/proto/grpc/testing/xds/v3/status.proto +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2020 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. - -// Local copy of Google status proto file, used for testing only. - - -syntax = "proto3"; - -package google.rpc; - -import "google/protobuf/any.proto"; - - -// The `Status` type defines a logical error model that is suitable for different -// programming environments, including REST APIs and RPC APIs. It is used by -// [gRPC](https://github.com/grpc). The error model is designed to be: -// -// - Simple to use and understand for most users -// - Flexible enough to meet unexpected needs -// -// # Overview -// -// The `Status` message contains three pieces of data: error code, error message, -// and error details. The error code should be an enum value of -// [google.rpc.Code][google.rpc.Code], but it may accept additional error codes if needed. The -// error message should be a developer-facing English message that helps -// developers *understand* and *resolve* the error. If a localized user-facing -// error message is needed, put the localized message in the error details or -// localize it in the client. The optional error details may contain arbitrary -// information about the error. There is a predefined set of error detail types -// in the package `google.rpc` that can be used for common error conditions. -// -// # Language mapping -// -// The `Status` message is the logical representation of the error model, but it -// is not necessarily the actual wire format. When the `Status` message is -// exposed in different client libraries and different wire protocols, it can be -// mapped differently. For example, it will likely be mapped to some exceptions -// in Java, but more likely mapped to some error codes in C. -// -// # Other uses -// -// The error model and the `Status` message can be used in a variety of -// environments, either with or without APIs, to provide a -// consistent developer experience across different environments. -// -// Example uses of this error model include: -// -// - Partial errors. If a service needs to return partial errors to the client, -// it may embed the `Status` in the normal response to indicate the partial -// errors. -// -// - Workflow errors. A typical workflow has multiple steps. Each step may -// have a `Status` message for error reporting. -// -// - Batch operations. If a client uses batch request and batch response, the -// `Status` message should be used directly inside batch response, one for -// each error sub-response. -// -// - Asynchronous operations. If an API call embeds asynchronous operation -// results in its response, the status of those operations should be -// represented directly using the `Status` message. -// -// - Logging. If some API errors are stored in logs, the message `Status` could -// be used directly after any stripping needed for security/privacy reasons. -message Status { - // The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. - int32 code = 1; - - // A developer-facing error message, which should be in English. Any - // user-facing error message should be localized and sent in the - // [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. - string message = 2; - - // A list of messages that carry the error details. There is a common set of - // message types for APIs to use. - repeated google.protobuf.Any details = 3; -} From 1a10109d106164f88df9450fe0bc3ddaee7506c5 Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 27 Jul 2020 14:04:55 -0700 Subject: [PATCH 37/45] xds testing: add path_matching and header_matching to cpp tests --- .../linux/grpc_xds_bazel_test_in_docker.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh index eee8876954d..9ed6eb7e0ad 100755 --- a/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh +++ b/tools/internal_ci/linux/grpc_xds_bazel_test_in_docker.sh @@ -48,12 +48,19 @@ touch "$TOOLS_DIR"/src/proto/grpc/testing/__init__.py bazel build test/cpp/interop:xds_interop_client +# Test cases "path_matching" and "header_matching" are not included in "all", +# because not all interop clients in all languages support these new tests. +# +# TODO: remove "path_matching" and "header_matching" from --test_case after +# they are added into "all". GRPC_VERBOSITY=debug GRPC_TRACE=xds_client,xds_resolver,xds_routing_lb,cds_lb,eds_lb,priority_lb,weighted_target_lb,lrs_lb "$PYTHON" \ tools/run_tests/run_xds_tests.py \ - --test_case=all \ + --test_case="all,path_matching,header_matching" \ --project_id=grpc-testing \ - --source_image=projects/grpc-testing/global/images/xds-test-server \ + --source_image=projects/grpc-testing/global/images/xds-test-server-2 \ --path_to_server_binary=/java_server/grpc-java/interop-testing/build/install/grpc-interop-testing/bin/xds-test-server \ --gcp_suffix=$(date '+%s') \ --verbose \ - --client_cmd='bazel-bin/test/cpp/interop/xds_interop_client --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps} {fail_on_failed_rpc}' + --client_cmd='bazel-bin/test/cpp/interop/xds_interop_client --server=xds:///{server_uri} --stats_port={stats_port} --qps={qps} {fail_on_failed_rpc} \ + {rpcs_to_send} \ + {metadata_to_send}' From 3ac116f1cb48acdb396e0d0df496db80bffdc169 Mon Sep 17 00:00:00 2001 From: Esun Kim Date: Tue, 30 Jun 2020 21:59:49 -0700 Subject: [PATCH 38/45] Enabled GPR_ABSEIL_SYNC --- BUILD | 2 ++ BUILD.gn | 2 ++ CMakeLists.txt | 15 ++++++++++----- Makefile | 8 ++++++++ build_autogenerated.yaml | 2 ++ config.m4 | 10 ++++++++++ config.w32 | 10 ++++++++++ gRPC-C++.podspec | 2 ++ gRPC-Core.podspec | 2 ++ grpc.gemspec | 18 ++++++++++++++++++ grpc.gyp | 2 ++ include/grpc/impl/codegen/port_platform.h | 2 +- package.xml | 18 ++++++++++++++++++ src/python/grpcio/grpc_core_dependencies.py | 8 ++++++++ 14 files changed, 95 insertions(+), 6 deletions(-) diff --git a/BUILD b/BUILD index 036c782ac30..d3f1b3b8258 100644 --- a/BUILD +++ b/BUILD @@ -553,9 +553,11 @@ grpc_cc_library( "src/core/lib/profiling/timers.h", ], external_deps = [ + "absl/base", "absl/memory", "absl/strings", "absl/strings:str_format", + "absl/synchronization", "absl/time:time", ], language = "c++", diff --git a/BUILD.gn b/BUILD.gn index 59835609c50..c9da5876e09 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -170,9 +170,11 @@ config("grpc_config") { ] deps = [ ":absl/time:time", + ":absl/synchronization:synchronization", ":absl/strings:strings", ":absl/strings:str_format", ":absl/memory:memory", + ":absl/base:base", ] public_configs = [ diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ec8476491a..ce52595111b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,9 +120,11 @@ set(gRPC_ABSL_USED_TARGETS absl_errno_saver absl_fixed_array absl_function_ref + absl_graphcycles_internal absl_inlined_vector absl_inlined_vector_internal absl_int128 + absl_kernel_timeout_internal absl_log_severity absl_malloc_internal absl_memory @@ -137,6 +139,7 @@ set(gRPC_ABSL_USED_TARGETS absl_strings absl_strings_internal absl_symbolize + absl_synchronization absl_throw_delegate absl_time absl_time_zone @@ -1313,9 +1316,11 @@ target_include_directories(gpr target_link_libraries(gpr ${_gRPC_ALLTARGETS_LIBRARIES} absl::time + absl::synchronization absl::strings absl::str_format absl::memory + absl::base ) if(_gRPC_PLATFORM_ANDROID) target_link_libraries(gpr @@ -15650,7 +15655,7 @@ generate_pkgconfig( "gRPC platform support library" "${gRPC_CORE_VERSION}" "" - "-lgpr -labsl_str_format_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" + "-lgpr -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" "" "gpr.pc") @@ -15660,7 +15665,7 @@ generate_pkgconfig( "high performance general RPC framework" "${gRPC_CORE_VERSION}" "gpr openssl" - "-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_status -labsl_cord -labsl_symbolize -labsl_demangle_internal -labsl_malloc_internal -labsl_stacktrace -labsl_debugging_internal -labsl_bad_optional_access -labsl_str_format_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" + "-lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" "" "grpc.pc") @@ -15670,7 +15675,7 @@ generate_pkgconfig( "high performance general RPC framework without SSL" "${gRPC_CORE_VERSION}" "gpr" - "-lgrpc_unsecure -labsl_status -labsl_cord -labsl_symbolize -labsl_demangle_internal -labsl_malloc_internal -labsl_stacktrace -labsl_debugging_internal -labsl_bad_optional_access -labsl_str_format_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" + "-lgrpc_unsecure -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" "" "grpc_unsecure.pc") @@ -15680,7 +15685,7 @@ generate_pkgconfig( "C++ wrapper for gRPC" "${gRPC_CPP_VERSION}" "grpc" - "-lgrpc++ -labsl_status -labsl_cord -labsl_symbolize -labsl_demangle_internal -labsl_malloc_internal -labsl_stacktrace -labsl_debugging_internal -labsl_bad_optional_access -labsl_str_format_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" + "-lgrpc++ -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" "" "grpc++.pc") @@ -15690,6 +15695,6 @@ generate_pkgconfig( "C++ wrapper for gRPC without SSL" "${gRPC_CPP_VERSION}" "grpc_unsecure" - "-lgrpc++_unsecure -labsl_status -labsl_cord -labsl_symbolize -labsl_demangle_internal -labsl_malloc_internal -labsl_stacktrace -labsl_debugging_internal -labsl_bad_optional_access -labsl_str_format_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" + "-lgrpc++_unsecure -labsl_status -labsl_cord -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_symbolize -labsl_demangle_internal -labsl_stacktrace -labsl_debugging_internal -labsl_malloc_internal -labsl_time -labsl_time_zone -labsl_civil_time -labsl_strings -labsl_strings_internal -labsl_throw_delegate -labsl_int128 -labsl_base -labsl_spinlock_wait -labsl_raw_logging_internal -labsl_log_severity -labsl_dynamic_annotations" "" "grpc++_unsecure.pc") diff --git a/Makefile b/Makefile index 91248fc8755..02fbccaf1d9 100644 --- a/Makefile +++ b/Makefile @@ -6515,6 +6515,14 @@ LIBGRPC_ABSEIL_SRC = \ third_party/abseil-cpp/absl/strings/str_split.cc \ third_party/abseil-cpp/absl/strings/string_view.cc \ third_party/abseil-cpp/absl/strings/substitute.cc \ + third_party/abseil-cpp/absl/synchronization/barrier.cc \ + third_party/abseil-cpp/absl/synchronization/blocking_counter.cc \ + third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc \ + third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc \ + third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc \ + third_party/abseil-cpp/absl/synchronization/internal/waiter.cc \ + third_party/abseil-cpp/absl/synchronization/mutex.cc \ + third_party/abseil-cpp/absl/synchronization/notification.cc \ third_party/abseil-cpp/absl/time/civil_time.cc \ third_party/abseil-cpp/absl/time/clock.cc \ third_party/abseil-cpp/absl/time/duration.cc \ diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index f5688a0cf32..6ec6783c45f 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -349,9 +349,11 @@ libs: - src/core/lib/profiling/stap_timers.cc deps: - absl/time:time + - absl/synchronization:synchronization - absl/strings:strings - absl/strings:str_format - absl/memory:memory + - absl/base:base secure: false - name: grpc build: all diff --git a/config.m4 b/config.m4 index d7383e49b81..98cdfae80c8 100644 --- a/config.m4 +++ b/config.m4 @@ -549,6 +549,14 @@ if test "$PHP_GRPC" != "no"; then third_party/abseil-cpp/absl/strings/str_split.cc \ third_party/abseil-cpp/absl/strings/string_view.cc \ third_party/abseil-cpp/absl/strings/substitute.cc \ + third_party/abseil-cpp/absl/synchronization/barrier.cc \ + third_party/abseil-cpp/absl/synchronization/blocking_counter.cc \ + third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc \ + third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc \ + third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc \ + third_party/abseil-cpp/absl/synchronization/internal/waiter.cc \ + third_party/abseil-cpp/absl/synchronization/mutex.cc \ + third_party/abseil-cpp/absl/synchronization/notification.cc \ third_party/abseil-cpp/absl/time/civil_time.cc \ third_party/abseil-cpp/absl/time/clock.cc \ third_party/abseil-cpp/absl/time/duration.cc \ @@ -989,6 +997,8 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/strings) PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/strings/internal) PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/strings/internal/str_format) + PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/synchronization) + PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/synchronization/internal) PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/time) PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/time/internal/cctz/src) PHP_ADD_BUILD_DIR($ext_builddir/third_party/abseil-cpp/absl/types) diff --git a/config.w32 b/config.w32 index f59f2618f7d..56758ed4162 100644 --- a/config.w32 +++ b/config.w32 @@ -517,6 +517,14 @@ if (PHP_GRPC != "no") { "third_party\\abseil-cpp\\absl\\strings\\str_split.cc " + "third_party\\abseil-cpp\\absl\\strings\\string_view.cc " + "third_party\\abseil-cpp\\absl\\strings\\substitute.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\barrier.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\blocking_counter.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\internal\\create_thread_identity.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\internal\\graphcycles.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\internal\\per_thread_sem.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\internal\\waiter.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\mutex.cc " + + "third_party\\abseil-cpp\\absl\\synchronization\\notification.cc " + "third_party\\abseil-cpp\\absl\\time\\civil_time.cc " + "third_party\\abseil-cpp\\absl\\time\\clock.cc " + "third_party\\abseil-cpp\\absl\\time\\duration.cc " + @@ -1037,6 +1045,8 @@ if (PHP_GRPC != "no") { FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\strings"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\strings\\internal"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\strings\\internal\\str_format"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\synchronization"); + FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\synchronization\\internal"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\time"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\time\\internal"); FSO.CreateFolder(base_dir+"\\ext\\grpc\\third_party\\abseil-cpp\\absl\\time\\internal\\cctz"); diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index c1f21867f5e..176b2094394 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -208,11 +208,13 @@ Pod::Spec.new do |s| ss.dependency "#{s.name}/Interface", version ss.dependency 'gRPC-Core', version abseil_version = '1.20200225.0' + ss.dependency 'abseil/base/base', abseil_version ss.dependency 'abseil/container/inlined_vector', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/status/status', abseil_version ss.dependency 'abseil/strings/str_format', abseil_version ss.dependency 'abseil/strings/strings', abseil_version + ss.dependency 'abseil/synchronization/synchronization', abseil_version ss.dependency 'abseil/time/time', abseil_version ss.dependency 'abseil/types/optional', abseil_version diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index fb351f7db61..63fbd793d29 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -174,11 +174,13 @@ Pod::Spec.new do |s| ss.dependency "#{s.name}/Interface", version ss.dependency 'BoringSSL-GRPC', '0.0.11' abseil_version = '1.20200225.0' + ss.dependency 'abseil/base/base', abseil_version ss.dependency 'abseil/container/inlined_vector', abseil_version ss.dependency 'abseil/memory/memory', abseil_version ss.dependency 'abseil/status/status', abseil_version ss.dependency 'abseil/strings/str_format', abseil_version ss.dependency 'abseil/strings/strings', abseil_version + ss.dependency 'abseil/synchronization/synchronization', abseil_version ss.dependency 'abseil/time/time', abseil_version ss.dependency 'abseil/types/optional', abseil_version ss.compiler_flags = '-DBORINGSSL_PREFIX=GRPC -Wno-unreachable-code -Wno-shorten-64-to-32' diff --git a/grpc.gemspec b/grpc.gemspec index 430651f443c..0a533cd8a42 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -1104,6 +1104,24 @@ Gem::Specification.new do |s| s.files += %w( third_party/abseil-cpp/absl/strings/strip.h ) s.files += %w( third_party/abseil-cpp/absl/strings/substitute.cc ) s.files += %w( third_party/abseil-cpp/absl/strings/substitute.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/barrier.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/barrier.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/blocking_counter.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/blocking_counter.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/graphcycles.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/waiter.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/internal/waiter.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/mutex.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/mutex.h ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/notification.cc ) + s.files += %w( third_party/abseil-cpp/absl/synchronization/notification.h ) s.files += %w( third_party/abseil-cpp/absl/time/civil_time.cc ) s.files += %w( third_party/abseil-cpp/absl/time/civil_time.h ) s.files += %w( third_party/abseil-cpp/absl/time/clock.cc ) diff --git a/grpc.gyp b/grpc.gyp index c7f9922bcd8..753c7b8211c 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -375,9 +375,11 @@ 'type': 'static_library', 'dependencies': [ 'absl/time:time', + 'absl/synchronization:synchronization', 'absl/strings:strings', 'absl/strings:str_format', 'absl/memory:memory', + 'absl/base:base', ], 'sources': [ 'src/core/lib/gpr/alloc.cc', diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 185e4481d0e..a3d3bb27b5a 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -31,7 +31,7 @@ * Defines GPR_ABSEIL_SYNC to use synchronization features from Abseil */ #ifndef GPR_ABSEIL_SYNC -/* #define GPR_ABSEIL_SYNC 1 */ +#define GPR_ABSEIL_SYNC 1 #endif /* Get windows.h included everywhere (we need it) */ diff --git a/package.xml b/package.xml index aa948d58f24..0d991d4d5c8 100644 --- a/package.xml +++ b/package.xml @@ -1106,6 +1106,24 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 28573461179..ef4d1aba717 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -516,6 +516,14 @@ CORE_SOURCE_FILES = [ 'third_party/abseil-cpp/absl/strings/str_split.cc', 'third_party/abseil-cpp/absl/strings/string_view.cc', 'third_party/abseil-cpp/absl/strings/substitute.cc', + 'third_party/abseil-cpp/absl/synchronization/barrier.cc', + 'third_party/abseil-cpp/absl/synchronization/blocking_counter.cc', + 'third_party/abseil-cpp/absl/synchronization/internal/create_thread_identity.cc', + 'third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc', + 'third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc', + 'third_party/abseil-cpp/absl/synchronization/internal/waiter.cc', + 'third_party/abseil-cpp/absl/synchronization/mutex.cc', + 'third_party/abseil-cpp/absl/synchronization/notification.cc', 'third_party/abseil-cpp/absl/time/civil_time.cc', 'third_party/abseil-cpp/absl/time/clock.cc', 'third_party/abseil-cpp/absl/time/duration.cc', From 92edd711cd7296031b1e8c86a28bebd4138a6ff6 Mon Sep 17 00:00:00 2001 From: Ivan Posva Date: Mon, 27 Jul 2020 21:14:37 -0700 Subject: [PATCH 39/45] Fix pagination in ServerNode::RenderServerSockets. --- src/core/lib/channel/channelz.cc | 27 +++++++++++------------ src/core/lib/channel/channelz_registry.cc | 4 +++- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index e42b1472487..a79a0147be3 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -310,27 +310,26 @@ void ServerNode::RemoveChildListenSocket(intptr_t child_uuid) { std::string ServerNode::RenderServerSockets(intptr_t start_socket_id, intptr_t max_results) { + GPR_ASSERT(start_socket_id >= 0); + GPR_ASSERT(max_results >= 0); // If user does not set max_results, we choose 500. size_t pagination_limit = max_results == 0 ? 500 : max_results; Json::Object object; { MutexLock lock(&child_mu_); size_t sockets_rendered = 0; - if (!child_sockets_.empty()) { - // Create list of socket refs. - Json::Array array; - const size_t limit = GPR_MIN(child_sockets_.size(), pagination_limit); - for (auto it = child_sockets_.lower_bound(start_socket_id); - it != child_sockets_.end() && sockets_rendered < limit; - ++it, ++sockets_rendered) { - array.emplace_back(Json::Object{ - {"socketId", std::to_string(it->first)}, - {"name", it->second->name()}, - }); - } - object["socketRef"] = std::move(array); + // Create list of socket refs. + Json::Array array; + auto it = child_sockets_.lower_bound(start_socket_id); + for (; it != child_sockets_.end() && sockets_rendered < pagination_limit; + ++it, ++sockets_rendered) { + array.emplace_back(Json::Object{ + {"socketId", std::to_string(it->first)}, + {"name", it->second->name()}, + }); } - if (sockets_rendered == child_sockets_.size()) object["end"] = true; + object["socketRef"] = std::move(array); + if (it == child_sockets_.end()) object["end"] = true; } Json json = std::move(object); return json.Dump(); diff --git a/src/core/lib/channel/channelz_registry.cc b/src/core/lib/channel/channelz_registry.cc index 43439363bf7..2739f5f53e5 100644 --- a/src/core/lib/channel/channelz_registry.cc +++ b/src/core/lib/channel/channelz_registry.cc @@ -208,10 +208,12 @@ char* grpc_channelz_get_server(intptr_t server_id) { char* grpc_channelz_get_server_sockets(intptr_t server_id, intptr_t start_socket_id, intptr_t max_results) { + // Validate inputs before handing them of to the renderer. grpc_core::RefCountedPtr base_node = grpc_core::channelz::ChannelzRegistry::Get(server_id); if (base_node == nullptr || - base_node->type() != grpc_core::channelz::BaseNode::EntityType::kServer) { + base_node->type() != grpc_core::channelz::BaseNode::EntityType::kServer || + start_socket_id < 0 || max_results < 0) { return nullptr; } // This cast is ok since we have just checked to make sure base_node is From 44a8ee928d49a0656c2b72f53c1c709d06c0ec5c Mon Sep 17 00:00:00 2001 From: ZHANG Dapeng Date: Tue, 28 Jul 2020 09:19:38 -0700 Subject: [PATCH 40/45] Fix string interpolation in run_xds_tests.py --- tools/run_tests/run_xds_tests.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/run_tests/run_xds_tests.py b/tools/run_tests/run_xds_tests.py index 5f6ffd431f0..4aeb1048125 100755 --- a/tools/run_tests/run_xds_tests.py +++ b/tools/run_tests/run_xds_tests.py @@ -576,7 +576,7 @@ def test_round_robin(gcp, backend_service, instance_group): if abs(stats.rpcs_by_peer[instance] - expected_requests) > threshold: raise Exception( 'RPC peer distribution differs from expected by more than %d ' - 'for instance %s (%s)', threshold, instance, stats) + 'for instance %s (%s)' % (threshold, instance, stats)) def test_secondary_locality_gets_no_requests_on_partial_primary_failure( @@ -774,8 +774,8 @@ def test_traffic_splitting(gcp, original_backend_service, instance_group, logger.info(e) if i == retry_count - 1: raise Exception( - 'RPC distribution (%s) differs from expected (%s)', - got_instance_percentage, expected_instance_percentage) + 'RPC distribution (%s) differs from expected (%s)' % + (got_instance_percentage, expected_instance_percentage)) else: logger.info("success") break @@ -1476,8 +1476,8 @@ def wait_for_global_operation(gcp, raise Exception(result['error']) return time.sleep(2) - raise Exception('Operation %s did not complete within %d', operation, - timeout_sec) + raise Exception('Operation %s did not complete within %d' % + (operation, timeout_sec)) def wait_for_zone_operation(gcp, @@ -1494,8 +1494,8 @@ def wait_for_zone_operation(gcp, raise Exception(result['error']) return time.sleep(2) - raise Exception('Operation %s did not complete within %d', operation, - timeout_sec) + raise Exception('Operation %s did not complete within %d' % + (operation, timeout_sec)) def wait_for_healthy_backends(gcp, From 1cdc78cb9e661a18f49e5265a1ceb469f7223d59 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 28 Jul 2020 09:54:17 -0700 Subject: [PATCH 41/45] Revert "Merge pull request #23562 from yang-g/one_core" This reverts commit f614b66a9833b1d223dbe12d0f8105ea5432cd23, reversing changes made to 5d803dcd3f24cbac609fa2390ff897b3243f14d2. --- src/core/lib/surface/completion_queue.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index bf99128e5b5..c59e329fabe 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -364,7 +364,7 @@ struct cq_callback_alternative_data { if (shared_cq_next == nullptr) { shared_cq_next = grpc_completion_queue_create_for_next(nullptr); - int num_nexting_threads = GPR_CLAMP(gpr_cpu_num_cores(), 1, 32); + int num_nexting_threads = GPR_CLAMP(gpr_cpu_num_cores(), 2, 32); threads_remaining.Store(num_nexting_threads, grpc_core::MemoryOrder::RELEASE); for (int i = 0; i < num_nexting_threads; i++) { From afa2bd836788e3067791a804479178adae13f2a2 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 28 Jul 2020 09:54:36 -0700 Subject: [PATCH 42/45] Revert "Merge pull request #23435 from vjpai/fix_iomgr_non_polling" This reverts commit 2d73a17587193380686ae36fc170962f286591f9, reversing changes made to 08d737abf8d8dac95a3c28e8deb2d744e2ce101d. --- src/core/lib/iomgr/iomgr.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index 9c97823dd6f..d7da7c9151d 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -31,7 +31,6 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/atomic.h" #include "src/core/lib/gprpp/global_config.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/buffer_list.h" @@ -51,7 +50,7 @@ static gpr_cv g_rcv; static int g_shutdown; static grpc_iomgr_object g_root_object; static bool g_grpc_abort_on_leaks; -static grpc_core::Atomic g_iomgr_non_polling{false}; +static bool g_iomgr_non_polling; void grpc_iomgr_init() { grpc_core::ExecCtx exec_ctx; @@ -196,9 +195,14 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object* obj) { bool grpc_iomgr_abort_on_leaks(void) { return g_grpc_abort_on_leaks; } bool grpc_iomgr_non_polling() { - return g_iomgr_non_polling.Load(grpc_core::MemoryOrder::SEQ_CST); + gpr_mu_lock(&g_mu); + bool ret = g_iomgr_non_polling; + gpr_mu_unlock(&g_mu); + return ret; } void grpc_iomgr_mark_non_polling_internal() { - g_iomgr_non_polling.Store(true, grpc_core::MemoryOrder::SEQ_CST); + gpr_mu_lock(&g_mu); + g_iomgr_non_polling = true; + gpr_mu_unlock(&g_mu); } From bcb65307179000b6ce64428dd6db8a58dffc5d86 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 28 Jul 2020 09:55:17 -0700 Subject: [PATCH 43/45] Revert "Merge pull request #23430 from vjpai/remove_do_not_test" This reverts commit 08d737abf8d8dac95a3c28e8deb2d744e2ce101d, reversing changes made to 6dc44b33c79a39dd072dc385617fc9470b161578. --- .../end2end/client_callback_end2end_test.cc | 62 ++++++++++++- test/cpp/end2end/end2end_test.cc | 86 ++++++++++++++++++- .../end2end/message_allocator_end2end_test.cc | 33 ++++++- 3 files changed, 177 insertions(+), 4 deletions(-) diff --git a/test/cpp/end2end/client_callback_end2end_test.cc b/test/cpp/end2end/client_callback_end2end_test.cc index 8a2d469ddf6..63e726d0cde 100644 --- a/test/cpp/end2end/client_callback_end2end_test.cc +++ b/test/cpp/end2end/client_callback_end2end_test.cc @@ -45,6 +45,17 @@ #include "test/cpp/util/string_ref_helper.h" #include "test/cpp/util/test_credentials_provider.h" +// MAYBE_SKIP_TEST is a macro to determine if this particular test configuration +// should be skipped based on a decision made at SetUp time. In particular, any +// callback tests can only be run if the iomgr can run in the background or if +// the transport is in-process. +#define MAYBE_SKIP_TEST \ + do { \ + if (do_not_test_) { \ + return; \ + } \ + } while (0) + namespace grpc { namespace testing { namespace { @@ -119,6 +130,10 @@ class ClientCallbackEnd2endTest server_ = builder.BuildAndStart(); is_server_started_ = true; + // if (GetParam().protocol == Protocol::TCP && + // !grpc_iomgr_run_in_background()) { + // do_not_test_ = true; + // } } void ResetStub() { @@ -352,6 +367,7 @@ class ClientCallbackEnd2endTest rpc.Await(); } } + bool do_not_test_{false}; bool is_server_started_{false}; int picked_port_{0}; std::shared_ptr channel_; @@ -364,11 +380,13 @@ class ClientCallbackEnd2endTest }; TEST_P(ClientCallbackEnd2endTest, SimpleRpc) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcs(1, false); } TEST_P(ClientCallbackEnd2endTest, SimpleRpcExpectedError) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; @@ -403,6 +421,7 @@ TEST_P(ClientCallbackEnd2endTest, SimpleRpcExpectedError) { } TEST_P(ClientCallbackEnd2endTest, SimpleRpcUnderLockNested) { + MAYBE_SKIP_TEST; ResetStub(); std::mutex mu1, mu2, mu3; std::condition_variable cv; @@ -453,6 +472,7 @@ TEST_P(ClientCallbackEnd2endTest, SimpleRpcUnderLockNested) { } TEST_P(ClientCallbackEnd2endTest, SimpleRpcUnderLock) { + MAYBE_SKIP_TEST; ResetStub(); std::mutex mu; std::condition_variable cv; @@ -480,16 +500,19 @@ TEST_P(ClientCallbackEnd2endTest, SimpleRpcUnderLock) { } TEST_P(ClientCallbackEnd2endTest, SequentialRpcs) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcs(10, false); } TEST_P(ClientCallbackEnd2endTest, SequentialRpcsRawReq) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcsRawReq(10); } TEST_P(ClientCallbackEnd2endTest, SendClientInitialMetadata) { + MAYBE_SKIP_TEST; ResetStub(); SimpleRequest request; SimpleResponse response; @@ -516,43 +539,51 @@ TEST_P(ClientCallbackEnd2endTest, SendClientInitialMetadata) { } TEST_P(ClientCallbackEnd2endTest, SimpleRpcWithBinaryMetadata) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcs(1, true); } TEST_P(ClientCallbackEnd2endTest, SequentialRpcsWithVariedBinaryMetadataValue) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcs(10, true); } TEST_P(ClientCallbackEnd2endTest, SequentialGenericRpcs) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcsGeneric(10, false); } TEST_P(ClientCallbackEnd2endTest, SequentialGenericRpcsAsBidi) { + MAYBE_SKIP_TEST; ResetStub(); SendGenericEchoAsBidi(10, 1, /*do_writes_done=*/true); } TEST_P(ClientCallbackEnd2endTest, SequentialGenericRpcsAsBidiWithReactorReuse) { + MAYBE_SKIP_TEST; ResetStub(); SendGenericEchoAsBidi(10, 10, /*do_writes_done=*/true); } TEST_P(ClientCallbackEnd2endTest, GenericRpcNoWritesDone) { + MAYBE_SKIP_TEST; ResetStub(); SendGenericEchoAsBidi(1, 1, /*do_writes_done=*/false); } #if GRPC_ALLOW_EXCEPTIONS TEST_P(ClientCallbackEnd2endTest, ExceptingRpc) { + MAYBE_SKIP_TEST; ResetStub(); SendRpcsGeneric(10, true); } #endif TEST_P(ClientCallbackEnd2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { + MAYBE_SKIP_TEST; ResetStub(); std::vector threads; threads.reserve(10); @@ -565,6 +596,7 @@ TEST_P(ClientCallbackEnd2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { } TEST_P(ClientCallbackEnd2endTest, MultipleRpcs) { + MAYBE_SKIP_TEST; ResetStub(); std::vector threads; threads.reserve(10); @@ -577,6 +609,7 @@ TEST_P(ClientCallbackEnd2endTest, MultipleRpcs) { } TEST_P(ClientCallbackEnd2endTest, CancelRpcBeforeStart) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -605,6 +638,7 @@ TEST_P(ClientCallbackEnd2endTest, CancelRpcBeforeStart) { } TEST_P(ClientCallbackEnd2endTest, RequestEchoServerCancel) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -735,6 +769,7 @@ class WriteClient : public grpc::experimental::ClientWriteReactor { }; TEST_P(ClientCallbackEnd2endTest, RequestStream) { + MAYBE_SKIP_TEST; ResetStub(); WriteClient test{stub_.get(), DO_NOT_CANCEL, 3}; test.Await(); @@ -745,6 +780,7 @@ TEST_P(ClientCallbackEnd2endTest, RequestStream) { } TEST_P(ClientCallbackEnd2endTest, ClientCancelsRequestStream) { + MAYBE_SKIP_TEST; ResetStub(); WriteClient test{stub_.get(), DO_NOT_CANCEL, 3, ClientCancelInfo{2}}; test.Await(); @@ -756,6 +792,7 @@ TEST_P(ClientCallbackEnd2endTest, ClientCancelsRequestStream) { // Server to cancel before doing reading the request TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelBeforeReads) { + MAYBE_SKIP_TEST; ResetStub(); WriteClient test{stub_.get(), CANCEL_BEFORE_PROCESSING, 1}; test.Await(); @@ -767,6 +804,7 @@ TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelBeforeReads) { // Server to cancel while reading a request from the stream in parallel TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelDuringRead) { + MAYBE_SKIP_TEST; ResetStub(); WriteClient test{stub_.get(), CANCEL_DURING_PROCESSING, 10}; test.Await(); @@ -779,6 +817,7 @@ TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelDuringRead) { // Server to cancel after reading all the requests but before returning to the // client TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelAfterReads) { + MAYBE_SKIP_TEST; ResetStub(); WriteClient test{stub_.get(), CANCEL_AFTER_PROCESSING, 4}; test.Await(); @@ -789,6 +828,7 @@ TEST_P(ClientCallbackEnd2endTest, RequestStreamServerCancelAfterReads) { } TEST_P(ClientCallbackEnd2endTest, UnaryReactor) { + MAYBE_SKIP_TEST; ResetStub(); class UnaryClient : public grpc::experimental::ClientUnaryReactor { public: @@ -847,6 +887,7 @@ TEST_P(ClientCallbackEnd2endTest, UnaryReactor) { } TEST_P(ClientCallbackEnd2endTest, GenericUnaryReactor) { + MAYBE_SKIP_TEST; ResetStub(); const std::string kMethodName("/grpc.testing.EchoTestService/Echo"); class UnaryClient : public grpc::experimental::ClientUnaryReactor { @@ -1012,6 +1053,7 @@ class ReadClient : public grpc::experimental::ClientReadReactor { }; TEST_P(ClientCallbackEnd2endTest, ResponseStream) { + MAYBE_SKIP_TEST; ResetStub(); ReadClient test{stub_.get(), DO_NOT_CANCEL}; test.Await(); @@ -1022,6 +1064,7 @@ TEST_P(ClientCallbackEnd2endTest, ResponseStream) { } TEST_P(ClientCallbackEnd2endTest, ClientCancelsResponseStream) { + MAYBE_SKIP_TEST; ResetStub(); ReadClient test{stub_.get(), DO_NOT_CANCEL, ClientCancelInfo{2}}; test.Await(); @@ -1031,6 +1074,7 @@ TEST_P(ClientCallbackEnd2endTest, ClientCancelsResponseStream) { // Server to cancel before sending any response messages TEST_P(ClientCallbackEnd2endTest, ResponseStreamServerCancelBefore) { + MAYBE_SKIP_TEST; ResetStub(); ReadClient test{stub_.get(), CANCEL_BEFORE_PROCESSING}; test.Await(); @@ -1042,6 +1086,7 @@ TEST_P(ClientCallbackEnd2endTest, ResponseStreamServerCancelBefore) { // Server to cancel while writing a response to the stream in parallel TEST_P(ClientCallbackEnd2endTest, ResponseStreamServerCancelDuring) { + MAYBE_SKIP_TEST; ResetStub(); ReadClient test{stub_.get(), CANCEL_DURING_PROCESSING}; test.Await(); @@ -1054,6 +1099,7 @@ TEST_P(ClientCallbackEnd2endTest, ResponseStreamServerCancelDuring) { // Server to cancel after writing all the respones to the stream but before // returning to the client TEST_P(ClientCallbackEnd2endTest, ResponseStreamServerCancelAfter) { + MAYBE_SKIP_TEST; ResetStub(); ReadClient test{stub_.get(), CANCEL_AFTER_PROCESSING}; test.Await(); @@ -1218,6 +1264,7 @@ class BidiClient }; TEST_P(ClientCallbackEnd2endTest, BidiStream) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), DO_NOT_CANCEL, kServerDefaultResponseStreamsToSend, @@ -1230,6 +1277,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStream) { } TEST_P(ClientCallbackEnd2endTest, BidiStreamFirstWriteAsync) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), DO_NOT_CANCEL, kServerDefaultResponseStreamsToSend, @@ -1242,6 +1290,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamFirstWriteAsync) { } TEST_P(ClientCallbackEnd2endTest, BidiStreamCorked) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), DO_NOT_CANCEL, kServerDefaultResponseStreamsToSend, @@ -1254,6 +1303,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamCorked) { } TEST_P(ClientCallbackEnd2endTest, BidiStreamCorkedFirstWriteAsync) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), DO_NOT_CANCEL, kServerDefaultResponseStreamsToSend, @@ -1266,6 +1316,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamCorkedFirstWriteAsync) { } TEST_P(ClientCallbackEnd2endTest, ClientCancelsBidiStream) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), DO_NOT_CANCEL, kServerDefaultResponseStreamsToSend, @@ -1280,6 +1331,7 @@ TEST_P(ClientCallbackEnd2endTest, ClientCancelsBidiStream) { // Server to cancel before reading/writing any requests/responses on the stream TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelBefore) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), CANCEL_BEFORE_PROCESSING, /*num_msgs_to_send=*/2, /*cork_metadata=*/false, /*first_write_async=*/false); @@ -1293,6 +1345,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelBefore) { // Server to cancel while reading/writing requests/responses on the stream in // parallel TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelDuring) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), CANCEL_DURING_PROCESSING, /*num_msgs_to_send=*/10, /*cork_metadata=*/false, @@ -1307,6 +1360,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelDuring) { // Server to cancel after reading/writing all requests/responses on the stream // but before returning to the client TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelAfter) { + MAYBE_SKIP_TEST; ResetStub(); BidiClient test(stub_.get(), CANCEL_AFTER_PROCESSING, /*num_msgs_to_send=*/5, /*cork_metadata=*/false, /*first_write_async=*/false); @@ -1318,6 +1372,7 @@ TEST_P(ClientCallbackEnd2endTest, BidiStreamServerCancelAfter) { } TEST_P(ClientCallbackEnd2endTest, SimultaneousReadAndWritesDone) { + MAYBE_SKIP_TEST; ResetStub(); class Client : public grpc::experimental::ClientBidiReactor { @@ -1365,6 +1420,7 @@ TEST_P(ClientCallbackEnd2endTest, SimultaneousReadAndWritesDone) { } TEST_P(ClientCallbackEnd2endTest, UnimplementedRpc) { + MAYBE_SKIP_TEST; ChannelArguments args; const auto& channel_creds = GetCredentialsProvider()->GetChannelCredentials( GetParam().credentials_type, &args); @@ -1399,6 +1455,7 @@ TEST_P(ClientCallbackEnd2endTest, UnimplementedRpc) { TEST_P(ClientCallbackEnd2endTest, ResponseStreamExtraReactionFlowReadsUntilDone) { + MAYBE_SKIP_TEST; ResetStub(); class ReadAllIncomingDataClient : public grpc::experimental::ClientReadReactor { @@ -1527,5 +1584,8 @@ INSTANTIATE_TEST_SUITE_P(ClientCallbackEnd2endTest, ClientCallbackEnd2endTest, int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); grpc::testing::TestEnvironment env(argc, argv); - return RUN_ALL_TESTS(); + grpc_init(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 82fbb0f2a6c..e6538344b03 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -62,6 +62,17 @@ using grpc::testing::EchoResponse; using grpc::testing::kTlsCredentialsType; using std::chrono::system_clock; +// MAYBE_SKIP_TEST is a macro to determine if this particular test configuration +// should be skipped based on a decision made at SetUp time. In particular, +// tests that use the callback server can only be run if the iomgr can run in +// the background or if the transport is in-process. +#define MAYBE_SKIP_TEST \ + do { \ + if (do_not_test_) { \ + return; \ + } \ + } while (0) + namespace grpc { namespace testing { namespace { @@ -316,6 +327,14 @@ class End2endTest : public ::testing::TestWithParam { GetParam().Log(); } + void SetUp() override { + // if (GetParam().callback_server && !GetParam().inproc && + // !grpc_iomgr_run_in_background()) { + // do_not_test_ = true; + // return; + // } + } + void TearDown() override { if (is_server_started_) { server_->Shutdown(); @@ -450,6 +469,7 @@ class End2endTest : public ::testing::TestWithParam { DummyInterceptor::Reset(); } + bool do_not_test_{false}; bool is_server_started_; std::shared_ptr channel_; std::unique_ptr stub_; @@ -505,6 +525,7 @@ class End2endServerTryCancelTest : public End2endTest { // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. void TestRequestStreamServerCancel( ServerTryCancelRequestPhase server_try_cancel, int num_msgs_to_send) { + MAYBE_SKIP_TEST; RestartServer(std::shared_ptr()); ResetStub(); EchoRequest request; @@ -583,6 +604,7 @@ class End2endServerTryCancelTest : public End2endTest { // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. void TestResponseStreamServerCancel( ServerTryCancelRequestPhase server_try_cancel) { + MAYBE_SKIP_TEST; RestartServer(std::shared_ptr()); ResetStub(); EchoRequest request; @@ -664,6 +686,7 @@ class End2endServerTryCancelTest : public End2endTest { // NOTE: Do not call this function with server_try_cancel == DO_NOT_CANCEL. void TestBidiStreamServerCancel(ServerTryCancelRequestPhase server_try_cancel, int num_messages) { + MAYBE_SKIP_TEST; RestartServer(std::shared_ptr()); ResetStub(); EchoRequest request; @@ -739,6 +762,7 @@ class End2endServerTryCancelTest : public End2endTest { }; TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -801,6 +825,7 @@ TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { } TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { + MAYBE_SKIP_TEST; // User-Agent is an HTTP header for HTTP transports only if (GetParam().inproc) { return; @@ -824,6 +849,7 @@ TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { } TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { + MAYBE_SKIP_TEST; ResetStub(); std::vector threads; threads.reserve(10); @@ -836,6 +862,7 @@ TEST_P(End2endTest, MultipleRpcsWithVariedBinaryMetadataValue) { } TEST_P(End2endTest, MultipleRpcs) { + MAYBE_SKIP_TEST; ResetStub(); std::vector threads; threads.reserve(10); @@ -848,6 +875,7 @@ TEST_P(End2endTest, MultipleRpcs) { } TEST_P(End2endTest, ManyStubs) { + MAYBE_SKIP_TEST; ResetStub(); ChannelTestPeer peer(channel_.get()); int registered_calls_pre = peer.registered_calls(); @@ -860,6 +888,7 @@ TEST_P(End2endTest, ManyStubs) { } TEST_P(End2endTest, EmptyBinaryMetadata) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -872,6 +901,7 @@ TEST_P(End2endTest, EmptyBinaryMetadata) { } TEST_P(End2endTest, ReconnectChannel) { + MAYBE_SKIP_TEST; if (GetParam().inproc) { return; } @@ -899,6 +929,7 @@ TEST_P(End2endTest, ReconnectChannel) { } TEST_P(End2endTest, RequestStreamOneRequest) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -915,6 +946,7 @@ TEST_P(End2endTest, RequestStreamOneRequest) { } TEST_P(End2endTest, RequestStreamOneRequestWithCoalescingApi) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -930,6 +962,7 @@ TEST_P(End2endTest, RequestStreamOneRequestWithCoalescingApi) { } TEST_P(End2endTest, RequestStreamTwoRequests) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -946,6 +979,7 @@ TEST_P(End2endTest, RequestStreamTwoRequests) { } TEST_P(End2endTest, RequestStreamTwoRequestsWithWriteThrough) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -962,6 +996,7 @@ TEST_P(End2endTest, RequestStreamTwoRequestsWithWriteThrough) { } TEST_P(End2endTest, RequestStreamTwoRequestsWithCoalescingApi) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -978,6 +1013,7 @@ TEST_P(End2endTest, RequestStreamTwoRequestsWithCoalescingApi) { } TEST_P(End2endTest, ResponseStream) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -996,6 +1032,7 @@ TEST_P(End2endTest, ResponseStream) { } TEST_P(End2endTest, ResponseStreamWithCoalescingApi) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1017,6 +1054,7 @@ TEST_P(End2endTest, ResponseStreamWithCoalescingApi) { // This was added to prevent regression from issue: // https://github.com/grpc/grpc/issues/11546 TEST_P(End2endTest, ResponseStreamWithEverythingCoalesced) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1038,6 +1076,7 @@ TEST_P(End2endTest, ResponseStreamWithEverythingCoalesced) { } TEST_P(End2endTest, BidiStream) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1062,6 +1101,7 @@ TEST_P(End2endTest, BidiStream) { } TEST_P(End2endTest, BidiStreamWithCoalescingApi) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1097,6 +1137,7 @@ TEST_P(End2endTest, BidiStreamWithCoalescingApi) { // This was added to prevent regression from issue: // https://github.com/grpc/grpc/issues/11546 TEST_P(End2endTest, BidiStreamWithEverythingCoalesced) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1122,6 +1163,7 @@ TEST_P(End2endTest, BidiStreamWithEverythingCoalesced) { // Talk to the two services with the same name but different package names. // The two stubs are created on the same channel. TEST_P(End2endTest, DiffPackageServices) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1150,6 +1192,7 @@ void CancelRpc(ClientContext* context, int delay_us, ServiceType* service) { } TEST_P(End2endTest, CancelRpcBeforeStart) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1165,6 +1208,7 @@ TEST_P(End2endTest, CancelRpcBeforeStart) { } TEST_P(End2endTest, CancelRpcAfterStart) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1201,6 +1245,7 @@ TEST_P(End2endTest, CancelRpcAfterStart) { // Client cancels request stream after sending two messages TEST_P(End2endTest, ClientCancelsRequestStream) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1224,6 +1269,7 @@ TEST_P(End2endTest, ClientCancelsRequestStream) { // Client cancels server stream after sending some messages TEST_P(End2endTest, ClientCancelsResponseStream) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1259,6 +1305,7 @@ TEST_P(End2endTest, ClientCancelsResponseStream) { // Client cancels bidi stream after sending some messages TEST_P(End2endTest, ClientCancelsBidi) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1294,6 +1341,7 @@ TEST_P(End2endTest, ClientCancelsBidi) { } TEST_P(End2endTest, RpcMaxMessageSize) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1316,6 +1364,7 @@ void ReaderThreadFunc(ClientReaderWriter* stream, // Run a Read and a WritesDone simultaneously. TEST_P(End2endTest, SimultaneousReadWritesDone) { + MAYBE_SKIP_TEST; ResetStub(); ClientContext context; gpr_event ev; @@ -1330,6 +1379,7 @@ TEST_P(End2endTest, SimultaneousReadWritesDone) { } TEST_P(End2endTest, ChannelState) { + MAYBE_SKIP_TEST; if (GetParam().inproc) { return; } @@ -1380,6 +1430,7 @@ TEST_P(End2endTest, ChannelStateTimeout) { // Talking to a non-existing service. TEST_P(End2endTest, NonExistingService) { + MAYBE_SKIP_TEST; ResetChannel(); std::unique_ptr stub; stub = grpc::testing::UnimplementedEchoService::NewStub(channel_); @@ -1397,6 +1448,7 @@ TEST_P(End2endTest, NonExistingService) { // Ask the server to send back a serialized proto in trailer. // This is an example of setting error details. TEST_P(End2endTest, BinaryTrailerTest) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1423,6 +1475,7 @@ TEST_P(End2endTest, BinaryTrailerTest) { } TEST_P(End2endTest, ExpectErrorTest) { + MAYBE_SKIP_TEST; ResetStub(); std::vector expected_status; @@ -1474,11 +1527,13 @@ class ProxyEnd2endTest : public End2endTest { }; TEST_P(ProxyEnd2endTest, SimpleRpc) { + MAYBE_SKIP_TEST; ResetStub(); SendRpc(stub_.get(), 1, false); } TEST_P(ProxyEnd2endTest, SimpleRpcWithEmptyMessages) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1489,6 +1544,7 @@ TEST_P(ProxyEnd2endTest, SimpleRpcWithEmptyMessages) { } TEST_P(ProxyEnd2endTest, MultipleRpcs) { + MAYBE_SKIP_TEST; ResetStub(); std::vector threads; threads.reserve(10); @@ -1502,6 +1558,7 @@ TEST_P(ProxyEnd2endTest, MultipleRpcs) { // Set a 10us deadline and make sure proper error is returned. TEST_P(ProxyEnd2endTest, RpcDeadlineExpires) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1527,6 +1584,7 @@ TEST_P(ProxyEnd2endTest, RpcDeadlineExpires) { // Set a long but finite deadline. TEST_P(ProxyEnd2endTest, RpcLongDeadline) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1543,6 +1601,7 @@ TEST_P(ProxyEnd2endTest, RpcLongDeadline) { // Ask server to echo back the deadline it sees. TEST_P(ProxyEnd2endTest, EchoDeadline) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1568,6 +1627,7 @@ TEST_P(ProxyEnd2endTest, EchoDeadline) { // Ask server to echo back the deadline it sees. The rpc has no deadline. TEST_P(ProxyEnd2endTest, EchoDeadlineForNoDeadlineRpc) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1583,6 +1643,7 @@ TEST_P(ProxyEnd2endTest, EchoDeadlineForNoDeadlineRpc) { } TEST_P(ProxyEnd2endTest, UnimplementedRpc) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1598,6 +1659,7 @@ TEST_P(ProxyEnd2endTest, UnimplementedRpc) { // Client cancels rpc after 10ms TEST_P(ProxyEnd2endTest, ClientCancelsRpc) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1632,6 +1694,7 @@ TEST_P(ProxyEnd2endTest, ClientCancelsRpc) { // Server cancels rpc after 1ms TEST_P(ProxyEnd2endTest, ServerCancelsRpc) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1646,6 +1709,7 @@ TEST_P(ProxyEnd2endTest, ServerCancelsRpc) { // Make the response larger than the flow control window. TEST_P(ProxyEnd2endTest, HugeResponse) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1663,6 +1727,7 @@ TEST_P(ProxyEnd2endTest, HugeResponse) { } TEST_P(ProxyEnd2endTest, Peer) { + MAYBE_SKIP_TEST; // Peer is not meaningful for inproc if (GetParam().inproc) { return; @@ -1691,6 +1756,7 @@ class SecureEnd2endTest : public End2endTest { }; TEST_P(SecureEnd2endTest, SimpleRpcWithHost) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; @@ -1722,6 +1788,7 @@ bool MetadataContains( } TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorSuccess) { + MAYBE_SKIP_TEST; auto* processor = new TestAuthMetadataProcessor(true); StartServer(std::shared_ptr(processor)); ResetStub(); @@ -1747,6 +1814,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorSuccess) { } TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { + MAYBE_SKIP_TEST; auto* processor = new TestAuthMetadataProcessor(true); StartServer(std::shared_ptr(processor)); ResetStub(); @@ -1762,6 +1830,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { } TEST_P(SecureEnd2endTest, SetPerCallCredentials) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1812,6 +1881,7 @@ class CredentialsInterceptorFactory }; TEST_P(SecureEnd2endTest, CallCredentialsInterception) { + MAYBE_SKIP_TEST; if (!GetParam().use_interceptors) { return; } @@ -1841,6 +1911,7 @@ TEST_P(SecureEnd2endTest, CallCredentialsInterception) { } TEST_P(SecureEnd2endTest, CallCredentialsInterceptionWithSetCredentials) { + MAYBE_SKIP_TEST; if (!GetParam().use_interceptors) { return; } @@ -1875,6 +1946,7 @@ TEST_P(SecureEnd2endTest, CallCredentialsInterceptionWithSetCredentials) { } TEST_P(SecureEnd2endTest, OverridePerCallCredentials) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1912,6 +1984,7 @@ TEST_P(SecureEnd2endTest, OverridePerCallCredentials) { } TEST_P(SecureEnd2endTest, AuthMetadataPluginKeyFailure) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1932,6 +2005,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginKeyFailure) { } TEST_P(SecureEnd2endTest, AuthMetadataPluginValueFailure) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -1951,6 +2025,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginValueFailure) { } TEST_P(SecureEnd2endTest, AuthMetadataPluginWithDeadline) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; request.mutable_param()->set_skip_cancelled_check(true); @@ -1976,6 +2051,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginWithDeadline) { } TEST_P(SecureEnd2endTest, AuthMetadataPluginWithCancel) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; request.mutable_param()->set_skip_cancelled_check(true); @@ -2004,6 +2080,7 @@ TEST_P(SecureEnd2endTest, AuthMetadataPluginWithCancel) { } TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginFailure) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -2027,6 +2104,7 @@ TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginFailure) { } TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorSuccess) { + MAYBE_SKIP_TEST; auto* processor = new TestAuthMetadataProcessor(false); StartServer(std::shared_ptr(processor)); ResetStub(); @@ -2055,6 +2133,7 @@ TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorSuccess) { } TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorFailure) { + MAYBE_SKIP_TEST; auto* processor = new TestAuthMetadataProcessor(false); StartServer(std::shared_ptr(processor)); ResetStub(); @@ -2073,6 +2152,7 @@ TEST_P(SecureEnd2endTest, NonBlockingAuthMetadataPluginAndProcessorFailure) { } TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginFailure) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -2096,6 +2176,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginFailure) { } TEST_P(SecureEnd2endTest, CompositeCallCreds) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -2128,6 +2209,7 @@ TEST_P(SecureEnd2endTest, CompositeCallCreds) { } TEST_P(SecureEnd2endTest, ClientAuthContext) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; EchoResponse response; @@ -2172,6 +2254,7 @@ class ResourceQuotaEnd2endTest : public End2endTest { }; TEST_P(ResourceQuotaEnd2endTest, SimpleRequest) { + MAYBE_SKIP_TEST; ResetStub(); EchoRequest request; @@ -2269,5 +2352,6 @@ INSTANTIATE_TEST_SUITE_P( int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int ret = RUN_ALL_TESTS(); + return ret; } diff --git a/test/cpp/end2end/message_allocator_end2end_test.cc b/test/cpp/end2end/message_allocator_end2end_test.cc index a21ea41eb63..95bf7f4faa1 100644 --- a/test/cpp/end2end/message_allocator_end2end_test.cc +++ b/test/cpp/end2end/message_allocator_end2end_test.cc @@ -45,6 +45,17 @@ #include "test/core/util/test_config.h" #include "test/cpp/util/test_credentials_provider.h" +// MAYBE_SKIP_TEST is a macro to determine if this particular test configuration +// should be skipped based on a decision made at SetUp time. In particular, any +// callback tests can only be run if the iomgr can run in the background or if +// the transport is in-process. +#define MAYBE_SKIP_TEST \ + do { \ + if (do_not_test_) { \ + return; \ + } \ + } while (0) + namespace grpc { namespace testing { namespace { @@ -106,7 +117,15 @@ void TestScenario::Log() const { class MessageAllocatorEnd2endTestBase : public ::testing::TestWithParam { protected: - MessageAllocatorEnd2endTestBase() { GetParam().Log(); } + MessageAllocatorEnd2endTestBase() { + GetParam().Log(); + // if (GetParam().protocol == Protocol::TCP) { + // if (!grpc_iomgr_run_in_background()) { + // do_not_test_ = true; + // return; + // } + // } + } ~MessageAllocatorEnd2endTestBase() = default; @@ -191,6 +210,7 @@ class MessageAllocatorEnd2endTestBase } } + bool do_not_test_{false}; int picked_port_{0}; std::shared_ptr channel_; std::unique_ptr stub_; @@ -202,6 +222,7 @@ class MessageAllocatorEnd2endTestBase class NullAllocatorTest : public MessageAllocatorEnd2endTestBase {}; TEST_P(NullAllocatorTest, SimpleRpc) { + MAYBE_SKIP_TEST; CreateServer(nullptr); ResetStub(); SendRpcs(1); @@ -257,6 +278,7 @@ class SimpleAllocatorTest : public MessageAllocatorEnd2endTestBase { }; TEST_P(SimpleAllocatorTest, SimpleRpc) { + MAYBE_SKIP_TEST; const int kRpcCount = 10; std::unique_ptr allocator(new SimpleAllocator); CreateServer(allocator.get()); @@ -271,6 +293,7 @@ TEST_P(SimpleAllocatorTest, SimpleRpc) { } TEST_P(SimpleAllocatorTest, RpcWithEarlyFreeRequest) { + MAYBE_SKIP_TEST; const int kRpcCount = 10; std::unique_ptr allocator(new SimpleAllocator); auto mutator = [](experimental::RpcAllocatorState* allocator_state, @@ -295,6 +318,7 @@ TEST_P(SimpleAllocatorTest, RpcWithEarlyFreeRequest) { } TEST_P(SimpleAllocatorTest, RpcWithReleaseRequest) { + MAYBE_SKIP_TEST; const int kRpcCount = 10; std::unique_ptr allocator(new SimpleAllocator); std::vector released_requests; @@ -354,6 +378,7 @@ class ArenaAllocatorTest : public MessageAllocatorEnd2endTestBase { }; TEST_P(ArenaAllocatorTest, SimpleRpc) { + MAYBE_SKIP_TEST; const int kRpcCount = 10; std::unique_ptr allocator(new ArenaAllocator); CreateServer(allocator.get()); @@ -404,6 +429,10 @@ INSTANTIATE_TEST_SUITE_P(ArenaAllocatorTest, ArenaAllocatorTest, int main(int argc, char** argv) { grpc::testing::TestEnvironment env(argc, argv); + // The grpc_init is to cover the MAYBE_SKIP_TEST. + grpc_init(); ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); + int ret = RUN_ALL_TESTS(); + grpc_shutdown(); + return ret; } From 9c5a39c6db06325f7590adb58ad4bde3457ef81c Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 28 Jul 2020 09:55:43 -0700 Subject: [PATCH 44/45] Revert "Merge pull request #23361 from vjpai/em_agnostic_core_callback_cq" This reverts commit a46cb5e86a8ec99fa423be61253c223914cdbf2a, reversing changes made to b5d42e75fb8a7180e40cdd8ed9f6c3a1b95f1f49. --- src/core/lib/iomgr/ev_posix.cc | 2 - src/core/lib/iomgr/iomgr.cc | 14 - src/core/lib/iomgr/iomgr.h | 10 - src/core/lib/surface/completion_queue.cc | 282 +----------------- src/core/lib/surface/completion_queue.h | 8 - src/core/lib/surface/init.cc | 2 - .../end2end/client_callback_end2end_test.cc | 8 +- test/cpp/end2end/end2end_test.cc | 10 +- .../end2end/message_allocator_end2end_test.cc | 12 +- test/cpp/microbenchmarks/bm_cq.cc | 62 +--- 10 files changed, 27 insertions(+), 383 deletions(-) diff --git a/src/core/lib/iomgr/ev_posix.cc b/src/core/lib/iomgr/ev_posix.cc index f0cb416447f..3d32359be46 100644 --- a/src/core/lib/iomgr/ev_posix.cc +++ b/src/core/lib/iomgr/ev_posix.cc @@ -37,7 +37,6 @@ #include "src/core/lib/iomgr/ev_epollex_linux.h" #include "src/core/lib/iomgr/ev_poll_posix.h" #include "src/core/lib/iomgr/internal_errqueue.h" -#include "src/core/lib/iomgr/iomgr.h" GPR_GLOBAL_CONFIG_DEFINE_STRING( grpc_poll_strategy, "all", @@ -108,7 +107,6 @@ const grpc_event_engine_vtable* init_non_polling(bool explicit_request) { auto ret = grpc_init_poll_posix(explicit_request); real_poll_function = grpc_poll_function; grpc_poll_function = dummy_poll; - grpc_iomgr_mark_non_polling_internal(); return ret; } diff --git a/src/core/lib/iomgr/iomgr.cc b/src/core/lib/iomgr/iomgr.cc index d7da7c9151d..802e3bdcb4d 100644 --- a/src/core/lib/iomgr/iomgr.cc +++ b/src/core/lib/iomgr/iomgr.cc @@ -50,7 +50,6 @@ static gpr_cv g_rcv; static int g_shutdown; static grpc_iomgr_object g_root_object; static bool g_grpc_abort_on_leaks; -static bool g_iomgr_non_polling; void grpc_iomgr_init() { grpc_core::ExecCtx exec_ctx; @@ -193,16 +192,3 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object* obj) { } bool grpc_iomgr_abort_on_leaks(void) { return g_grpc_abort_on_leaks; } - -bool grpc_iomgr_non_polling() { - gpr_mu_lock(&g_mu); - bool ret = g_iomgr_non_polling; - gpr_mu_unlock(&g_mu); - return ret; -} - -void grpc_iomgr_mark_non_polling_internal() { - gpr_mu_lock(&g_mu); - g_iomgr_non_polling = true; - gpr_mu_unlock(&g_mu); -} diff --git a/src/core/lib/iomgr/iomgr.h b/src/core/lib/iomgr/iomgr.h index cb9f3eb35c8..e02f15e551c 100644 --- a/src/core/lib/iomgr/iomgr.h +++ b/src/core/lib/iomgr/iomgr.h @@ -45,16 +45,6 @@ void grpc_iomgr_shutdown_background_closure(); */ bool grpc_iomgr_run_in_background(); -/* Returns true if polling engine is non-polling, false otherwise. - * Currently only 'none' is non-polling. - */ -bool grpc_iomgr_non_polling(); - -/* Mark the polling engine as non-polling. For internal use only. - * Currently only 'none' is non-polling. - */ -void grpc_iomgr_mark_non_polling_internal(); - /** Returns true if the caller is a worker thread for any background poller. */ bool grpc_iomgr_is_any_background_poller_thread(); diff --git a/src/core/lib/surface/completion_queue.cc b/src/core/lib/surface/completion_queue.cc index c59e329fabe..a9f65bd5310 100644 --- a/src/core/lib/surface/completion_queue.cc +++ b/src/core/lib/surface/completion_queue.cc @@ -39,7 +39,6 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/tls.h" #include "src/core/lib/gprpp/atomic.h" -#include "src/core/lib/iomgr/closure.h" #include "src/core/lib/iomgr/executor.h" #include "src/core/lib/iomgr/pollset.h" #include "src/core/lib/iomgr/timer.h" @@ -209,9 +208,6 @@ struct cq_vtable { void* reserved); grpc_event (*pluck)(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved); - // TODO(vjpai): Remove proxy_pollset once callback_alternative no longer - // needed. - grpc_pollset* (*proxy_pollset)(grpc_completion_queue* cq); }; namespace { @@ -313,7 +309,7 @@ struct cq_pluck_data { }; struct cq_callback_data { - explicit cq_callback_data( + cq_callback_data( grpc_experimental_completion_queue_functor* shutdown_callback) : shutdown_callback(shutdown_callback) {} @@ -338,81 +334,6 @@ struct cq_callback_data { grpc_experimental_completion_queue_functor* shutdown_callback; }; -// TODO(vjpai): Remove all callback_alternative variants when event manager is -// the only supported poller. -struct cq_callback_alternative_data { - explicit cq_callback_alternative_data( - grpc_experimental_completion_queue_functor* shutdown_callback) - : implementation(SharedNextableCQ()), - shutdown_callback(shutdown_callback) {} - - /* This just points to a single shared nextable CQ */ - grpc_completion_queue* const implementation; - - /** Number of outstanding events (+1 if not shut down) - Initial count is dropped by grpc_completion_queue_shutdown */ - grpc_core::Atomic pending_events{1}; - - /** 0 initially. 1 once we initiated shutdown */ - bool shutdown_called = false; - - /** A callback that gets invoked when the CQ completes shutdown */ - grpc_experimental_completion_queue_functor* shutdown_callback; - - static grpc_completion_queue* SharedNextableCQ() { - grpc_core::MutexLock lock(&*shared_cq_next_mu); - - if (shared_cq_next == nullptr) { - shared_cq_next = grpc_completion_queue_create_for_next(nullptr); - int num_nexting_threads = GPR_CLAMP(gpr_cpu_num_cores(), 2, 32); - threads_remaining.Store(num_nexting_threads, - grpc_core::MemoryOrder::RELEASE); - for (int i = 0; i < num_nexting_threads; i++) { - grpc_core::Executor::Run( - GRPC_CLOSURE_CREATE( - [](void* arg, grpc_error* /*error*/) { - grpc_completion_queue* cq = - static_cast(arg); - while (true) { - grpc_event event = grpc_completion_queue_next( - cq, gpr_inf_future(GPR_CLOCK_REALTIME), nullptr); - if (event.type == GRPC_QUEUE_SHUTDOWN) { - break; - } - GPR_DEBUG_ASSERT(event.type == GRPC_OP_COMPLETE); - // We can always execute the callback inline rather than - // pushing it to another Executor thread because this - // thread is definitely running on an executor, does not - // hold any application locks before executing the callback, - // and cannot be entered recursively. - auto* functor = static_cast< - grpc_experimental_completion_queue_functor*>(event.tag); - functor->functor_run(functor, event.success); - } - if (threads_remaining.FetchSub( - 1, grpc_core::MemoryOrder::ACQ_REL) == 1) { - grpc_completion_queue_destroy(cq); - } - }, - shared_cq_next, nullptr), - GRPC_ERROR_NONE, grpc_core::ExecutorType::DEFAULT, - grpc_core::ExecutorJobType::LONG); - } - } - return shared_cq_next; - } - // Use manually-constructed Mutex to avoid static construction issues - static grpc_core::ManualConstructor shared_cq_next_mu; - static grpc_completion_queue* - shared_cq_next; // GUARDED_BY(shared_cq_next_mu) - static grpc_core::Atomic threads_remaining; -}; - -grpc_core::ManualConstructor - cq_callback_alternative_data::shared_cq_next_mu; -grpc_completion_queue* cq_callback_alternative_data::shared_cq_next = nullptr; -grpc_core::Atomic cq_callback_alternative_data::threads_remaining{0}; - } // namespace /* Completion queue structure */ @@ -425,12 +346,6 @@ struct grpc_completion_queue { const cq_vtable* vtable; const cq_poller_vtable* poller_vtable; - // The pollset entry is allowed to enable proxy CQs like the - // callback_alternative. - // TODO(vjpai): Consider removing pollset and reverting to previous - // calculation of pollset once callback_alternative is no longer needed. - grpc_pollset* pollset; - #ifndef NDEBUG void** outstanding_tags; size_t outstanding_tag_count; @@ -445,17 +360,13 @@ struct grpc_completion_queue { static void cq_finish_shutdown_next(grpc_completion_queue* cq); static void cq_finish_shutdown_pluck(grpc_completion_queue* cq); static void cq_finish_shutdown_callback(grpc_completion_queue* cq); -static void cq_finish_shutdown_callback_alternative(grpc_completion_queue* cq); static void cq_shutdown_next(grpc_completion_queue* cq); static void cq_shutdown_pluck(grpc_completion_queue* cq); static void cq_shutdown_callback(grpc_completion_queue* cq); -static void cq_shutdown_callback_alternative(grpc_completion_queue* cq); static bool cq_begin_op_for_next(grpc_completion_queue* cq, void* tag); static bool cq_begin_op_for_pluck(grpc_completion_queue* cq, void* tag); static bool cq_begin_op_for_callback(grpc_completion_queue* cq, void* tag); -static bool cq_begin_op_for_callback_alternative(grpc_completion_queue* cq, - void* tag); // A cq_end_op function is called when an operation on a given CQ with // a given tag has completed. The storage argument is a reference to the @@ -478,20 +389,12 @@ static void cq_end_op_for_callback( void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage, bool internal); -static void cq_end_op_for_callback_alternative( - grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, - grpc_cq_completion* storage, bool internal); - static grpc_event cq_next(grpc_completion_queue* cq, gpr_timespec deadline, void* reserved); static grpc_event cq_pluck(grpc_completion_queue* cq, void* tag, gpr_timespec deadline, void* reserved); -static grpc_pollset* cq_proxy_pollset_for_callback_alternative( - grpc_completion_queue* cq); - // Note that cq_init_next and cq_init_pluck do not use the shutdown_callback static void cq_init_next( void* data, grpc_experimental_completion_queue_functor* shutdown_callback); @@ -499,39 +402,29 @@ static void cq_init_pluck( void* data, grpc_experimental_completion_queue_functor* shutdown_callback); static void cq_init_callback( void* data, grpc_experimental_completion_queue_functor* shutdown_callback); -// poller becomes only option. -static void cq_init_callback_alternative( - void* data, grpc_experimental_completion_queue_functor* shutdown_callback); static void cq_destroy_next(void* data); static void cq_destroy_pluck(void* data); static void cq_destroy_callback(void* data); -static void cq_destroy_callback_alternative(void* data); /* Completion queue vtables based on the completion-type */ -// TODO(vjpai): Make this const again once we stop needing callback_alternative -static cq_vtable g_polling_cq_vtable[] = { +static const cq_vtable g_cq_vtable[] = { /* GRPC_CQ_NEXT */ {GRPC_CQ_NEXT, sizeof(cq_next_data), cq_init_next, cq_shutdown_next, cq_destroy_next, cq_begin_op_for_next, cq_end_op_for_next, cq_next, - nullptr, nullptr}, + nullptr}, /* GRPC_CQ_PLUCK */ {GRPC_CQ_PLUCK, sizeof(cq_pluck_data), cq_init_pluck, cq_shutdown_pluck, cq_destroy_pluck, cq_begin_op_for_pluck, cq_end_op_for_pluck, nullptr, - cq_pluck, nullptr}, + cq_pluck}, /* GRPC_CQ_CALLBACK */ {GRPC_CQ_CALLBACK, sizeof(cq_callback_data), cq_init_callback, cq_shutdown_callback, cq_destroy_callback, cq_begin_op_for_callback, - cq_end_op_for_callback, nullptr, nullptr, nullptr}, + cq_end_op_for_callback, nullptr, nullptr}, }; -// Separate vtable for non-polling cqs, assign at init -static cq_vtable g_nonpolling_cq_vtable[sizeof(g_polling_cq_vtable) / - sizeof(g_polling_cq_vtable[0])]; - #define DATA_FROM_CQ(cq) ((void*)(cq + 1)) -#define INLINE_POLLSET_FROM_CQ(cq) \ +#define POLLSET_FROM_CQ(cq) \ ((grpc_pollset*)(cq->vtable->data_size + (char*)DATA_FROM_CQ(cq))) -#define POLLSET_FROM_CQ(cq) (cq->pollset) grpc_core::TraceFlag grpc_cq_pluck_trace(false, "queue_pluck"); @@ -550,46 +443,6 @@ static void on_pollset_shutdown_done(void* cq, grpc_error* error); void grpc_cq_global_init() { gpr_tls_init(&g_cached_event); gpr_tls_init(&g_cached_cq); - g_nonpolling_cq_vtable[GRPC_CQ_NEXT] = g_polling_cq_vtable[GRPC_CQ_NEXT]; - g_nonpolling_cq_vtable[GRPC_CQ_PLUCK] = g_polling_cq_vtable[GRPC_CQ_PLUCK]; - g_nonpolling_cq_vtable[GRPC_CQ_CALLBACK] = - g_polling_cq_vtable[GRPC_CQ_CALLBACK]; -} - -// TODO(vjpai): Remove when callback_alternative is no longer needed -void grpc_cq_init() { - // If the iomgr runs in the background, we can use the preferred callback CQ. - // If the iomgr is non-polling, we cannot use the alternative callback CQ. - if (!grpc_iomgr_run_in_background() && !grpc_iomgr_non_polling()) { - cq_callback_alternative_data::shared_cq_next_mu.Init(); - g_polling_cq_vtable[GRPC_CQ_CALLBACK] = { - GRPC_CQ_CALLBACK, - sizeof(cq_callback_alternative_data), - cq_init_callback_alternative, - cq_shutdown_callback_alternative, - cq_destroy_callback_alternative, - cq_begin_op_for_callback_alternative, - cq_end_op_for_callback_alternative, - nullptr, - nullptr, - cq_proxy_pollset_for_callback_alternative}; - } -} - -// TODO(vjpai): Remove when callback_alternative is no longer needed -void grpc_cq_shutdown() { - if (!grpc_iomgr_run_in_background() && !grpc_iomgr_non_polling()) { - { - grpc_core::MutexLock lock( - &*cq_callback_alternative_data::shared_cq_next_mu); - if (cq_callback_alternative_data::shared_cq_next != nullptr) { - grpc_completion_queue_shutdown( - cq_callback_alternative_data::shared_cq_next); - } - cq_callback_alternative_data::shared_cq_next = nullptr; - } - cq_callback_alternative_data::shared_cq_next_mu.Destroy(); - } } void grpc_completion_queue_thread_local_cache_init(grpc_completion_queue* cq) { @@ -668,9 +521,7 @@ grpc_completion_queue* grpc_completion_queue_create_internal( "polling_type=%d)", 2, (completion_type, polling_type)); - const cq_vtable* vtable = (polling_type == GRPC_CQ_NON_POLLING) - ? &g_nonpolling_cq_vtable[completion_type] - : &g_polling_cq_vtable[completion_type]; + const cq_vtable* vtable = &g_cq_vtable[completion_type]; const cq_poller_vtable* poller_vtable = &g_poller_vtable_by_poller_type[polling_type]; @@ -687,18 +538,9 @@ grpc_completion_queue* grpc_completion_queue_create_internal( /* One for destroy(), one for pollset_shutdown */ new (&cq->owning_refs) grpc_core::RefCount(2); + poller_vtable->init(POLLSET_FROM_CQ(cq), &cq->mu); vtable->init(DATA_FROM_CQ(cq), shutdown_callback); - // TODO(vjpai): When callback_alternative is no longer needed, cq->pollset can - // be removed and the nullptr proxy_pollset value below can be the definition - // of POLLSET_FROM_CQ. - cq->pollset = cq->vtable->proxy_pollset == nullptr - ? INLINE_POLLSET_FROM_CQ(cq) - : cq->vtable->proxy_pollset(cq); - // Init the inline pollset. If a proxy CQ is used, the proxy pollset will be - // init'ed in its CQ init. - cq->poller_vtable->init(INLINE_POLLSET_FROM_CQ(cq), &cq->mu); - GRPC_CLOSURE_INIT(&cq->pollset_shutdown_done, on_pollset_shutdown_done, cq, grpc_schedule_on_exec_ctx); return cq; @@ -736,17 +578,6 @@ static void cq_destroy_callback(void* data) { cqd->~cq_callback_data(); } -static void cq_init_callback_alternative( - void* data, grpc_experimental_completion_queue_functor* shutdown_callback) { - new (data) cq_callback_alternative_data(shutdown_callback); -} - -static void cq_destroy_callback_alternative(void* data) { - cq_callback_alternative_data* cqd = - static_cast(data); - cqd->~cq_callback_alternative_data(); -} - grpc_cq_completion_type grpc_get_cq_completion_type(grpc_completion_queue* cq) { return cq->vtable->cq_completion_type; } @@ -787,9 +618,7 @@ void grpc_cq_internal_unref(grpc_completion_queue* cq) { #endif if (GPR_UNLIKELY(cq->owning_refs.Unref(debug_location, reason))) { cq->vtable->destroy(DATA_FROM_CQ(cq)); - // Only destroy the inlined pollset. If a proxy CQ is used, the proxy - // pollset will be destroyed by the proxy CQ. - cq->poller_vtable->destroy(INLINE_POLLSET_FROM_CQ(cq)); + cq->poller_vtable->destroy(POLLSET_FROM_CQ(cq)); #ifndef NDEBUG gpr_free(cq->outstanding_tags); #endif @@ -840,14 +669,6 @@ static bool cq_begin_op_for_callback(grpc_completion_queue* cq, void* /*tag*/) { return cqd->pending_events.IncrementIfNonzero(); } -static bool cq_begin_op_for_callback_alternative(grpc_completion_queue* cq, - void* tag) { - cq_callback_alternative_data* cqd = - static_cast DATA_FROM_CQ(cq); - return grpc_cq_begin_op(cqd->implementation, tag) && - cqd->pending_events.IncrementIfNonzero(); -} - bool grpc_cq_begin_op(grpc_completion_queue* cq, void* tag) { #ifndef NDEBUG gpr_mu_lock(cq->mu); @@ -1011,7 +832,7 @@ static void cq_end_op_for_pluck( GRPC_ERROR_UNREF(error); } -void functor_callback(void* arg, grpc_error* error) { +static void functor_callback(void* arg, grpc_error* error) { auto* functor = static_cast(arg); functor->functor_run(functor, error == GRPC_ERROR_NONE); } @@ -1071,40 +892,6 @@ static void cq_end_op_for_callback( GRPC_CLOSURE_CREATE(functor_callback, functor, nullptr), error); } -static void cq_end_op_for_callback_alternative( - grpc_completion_queue* cq, void* tag, grpc_error* error, - void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, - grpc_cq_completion* storage, bool internal) { - GPR_TIMER_SCOPE("cq_end_op_for_callback_alternative", 0); - - cq_callback_alternative_data* cqd = - static_cast DATA_FROM_CQ(cq); - - if (GRPC_TRACE_FLAG_ENABLED(grpc_api_trace) || - (GRPC_TRACE_FLAG_ENABLED(grpc_trace_operation_failures) && - error != GRPC_ERROR_NONE)) { - const char* errmsg = grpc_error_string(error); - GRPC_API_TRACE( - "cq_end_op_for_callback_alternative(cq=%p, tag=%p, error=%s, " - "done=%p, done_arg=%p, storage=%p)", - 6, (cq, tag, errmsg, done, done_arg, storage)); - if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_operation_failures) && - error != GRPC_ERROR_NONE) { - gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); - } - } - - // Pass through the actual work to the internal nextable CQ - grpc_cq_end_op(cqd->implementation, tag, error, done, done_arg, storage, - internal); - - cq_check_tag(cq, tag, true); /* Used in debug builds only */ - - if (cqd->pending_events.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1) { - cq_finish_shutdown_callback_alternative(cq); - } -} - void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error, void (*done)(void* done_arg, grpc_cq_completion* storage), void* done_arg, grpc_cq_completion* storage, @@ -1112,13 +899,6 @@ void grpc_cq_end_op(grpc_completion_queue* cq, void* tag, grpc_error* error, cq->vtable->end_op(cq, tag, error, done, done_arg, storage, internal); } -static grpc_pollset* cq_proxy_pollset_for_callback_alternative( - grpc_completion_queue* cq) { - cq_callback_alternative_data* cqd = - static_cast(DATA_FROM_CQ(cq)); - return POLLSET_FROM_CQ(cqd->implementation); -} - struct cq_is_finished_arg { gpr_atm last_seen_things_queued_ever; grpc_completion_queue* cq; @@ -1599,21 +1379,6 @@ static void cq_finish_shutdown_callback(grpc_completion_queue* cq) { GRPC_ERROR_NONE); } -static void cq_finish_shutdown_callback_alternative(grpc_completion_queue* cq) { - cq_callback_alternative_data* cqd = - static_cast DATA_FROM_CQ(cq); - auto* callback = cqd->shutdown_callback; - - GPR_ASSERT(cqd->shutdown_called); - - // Shutdown the non-proxy pollset - cq->poller_vtable->shutdown(INLINE_POLLSET_FROM_CQ(cq), - &cq->pollset_shutdown_done); - grpc_core::Executor::Run( - GRPC_CLOSURE_CREATE(functor_callback, callback, nullptr), - GRPC_ERROR_NONE); -} - static void cq_shutdown_callback(grpc_completion_queue* cq) { cq_callback_data* cqd = static_cast DATA_FROM_CQ(cq); @@ -1640,33 +1405,6 @@ static void cq_shutdown_callback(grpc_completion_queue* cq) { GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (callback cq)"); } -static void cq_shutdown_callback_alternative(grpc_completion_queue* cq) { - cq_callback_alternative_data* cqd = - static_cast DATA_FROM_CQ(cq); - - /* Need an extra ref for cq here because: - * We call cq_finish_shutdown_callback() below, which calls pollset shutdown. - * Pollset shutdown decrements the cq ref count which can potentially destroy - * the cq (if that happens to be the last ref). - * Creating an extra ref here prevents the cq from getting destroyed while - * this function is still active */ - GRPC_CQ_INTERNAL_REF(cq, "shutting_down (callback cq)"); - gpr_mu_lock(cq->mu); - if (cqd->shutdown_called) { - gpr_mu_unlock(cq->mu); - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (callback cq)"); - return; - } - cqd->shutdown_called = true; - if (cqd->pending_events.FetchSub(1, grpc_core::MemoryOrder::ACQ_REL) == 1) { - gpr_mu_unlock(cq->mu); - cq_finish_shutdown_callback_alternative(cq); - } else { - gpr_mu_unlock(cq->mu); - } - GRPC_CQ_INTERNAL_UNREF(cq, "shutting_down (callback cq)"); -} - /* Shutdown simply drops a ref that we reserved at creation time; if we drop to zero here, then enter shutdown mode and wake up any waiters */ void grpc_completion_queue_shutdown(grpc_completion_queue* cq) { diff --git a/src/core/lib/surface/completion_queue.h b/src/core/lib/surface/completion_queue.h index 002f7b0728b..4a114be8285 100644 --- a/src/core/lib/surface/completion_queue.h +++ b/src/core/lib/surface/completion_queue.h @@ -69,14 +69,6 @@ void grpc_cq_internal_unref(grpc_completion_queue* cc); /* Initializes global variables used by completion queues */ void grpc_cq_global_init(); -// Completion queue initializations that must be done after iomgr -// TODO(vjpai): Remove when callback_alternative is no longer needed. -void grpc_cq_init(); - -// Completion queue shutdowns that must be done before iomgr shutdown. -// TODO(vjpai): Remove when callback_alternative is no longer needed. -void grpc_cq_shutdown(); - /* Flag that an operation is beginning: the completion channel will not finish shutdown until a corrensponding grpc_cq_end_* call is made. \a tag is currently used only in debug builds. Return true on success, and diff --git a/src/core/lib/surface/init.cc b/src/core/lib/surface/init.cc index 3bbd7dc53d6..d8bc4e4dd32 100644 --- a/src/core/lib/surface/init.cc +++ b/src/core/lib/surface/init.cc @@ -144,7 +144,6 @@ void grpc_init(void) { grpc_core::ApplicationCallbackExecCtx::GlobalInit(); grpc_core::ExecCtx::GlobalInit(); grpc_iomgr_init(); - grpc_cq_init(); gpr_timers_global_init(); grpc_core::HandshakerRegistry::Init(); grpc_security_init(); @@ -170,7 +169,6 @@ void grpc_shutdown_internal_locked(void) { int i; { grpc_core::ExecCtx exec_ctx(0); - grpc_cq_shutdown(); grpc_iomgr_shutdown_background_closure(); { grpc_timer_manager_set_threading(false); // shutdown timer_manager thread diff --git a/test/cpp/end2end/client_callback_end2end_test.cc b/test/cpp/end2end/client_callback_end2end_test.cc index 63e726d0cde..5387e5f0af9 100644 --- a/test/cpp/end2end/client_callback_end2end_test.cc +++ b/test/cpp/end2end/client_callback_end2end_test.cc @@ -130,10 +130,10 @@ class ClientCallbackEnd2endTest server_ = builder.BuildAndStart(); is_server_started_ = true; - // if (GetParam().protocol == Protocol::TCP && - // !grpc_iomgr_run_in_background()) { - // do_not_test_ = true; - // } + if (GetParam().protocol == Protocol::TCP && + !grpc_iomgr_run_in_background()) { + do_not_test_ = true; + } } void ResetStub() { diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index e6538344b03..f157d20cc6f 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -328,11 +328,11 @@ class End2endTest : public ::testing::TestWithParam { } void SetUp() override { - // if (GetParam().callback_server && !GetParam().inproc && - // !grpc_iomgr_run_in_background()) { - // do_not_test_ = true; - // return; - // } + if (GetParam().callback_server && !GetParam().inproc && + !grpc_iomgr_run_in_background()) { + do_not_test_ = true; + return; + } } void TearDown() override { diff --git a/test/cpp/end2end/message_allocator_end2end_test.cc b/test/cpp/end2end/message_allocator_end2end_test.cc index 95bf7f4faa1..c15066794bc 100644 --- a/test/cpp/end2end/message_allocator_end2end_test.cc +++ b/test/cpp/end2end/message_allocator_end2end_test.cc @@ -119,12 +119,12 @@ class MessageAllocatorEnd2endTestBase protected: MessageAllocatorEnd2endTestBase() { GetParam().Log(); - // if (GetParam().protocol == Protocol::TCP) { - // if (!grpc_iomgr_run_in_background()) { - // do_not_test_ = true; - // return; - // } - // } + if (GetParam().protocol == Protocol::TCP) { + if (!grpc_iomgr_run_in_background()) { + do_not_test_ = true; + return; + } + } } ~MessageAllocatorEnd2endTestBase() = default; diff --git a/test/cpp/microbenchmarks/bm_cq.cc b/test/cpp/microbenchmarks/bm_cq.cc index 1640c4d52f0..c53eb2b9413 100644 --- a/test/cpp/microbenchmarks/bm_cq.cc +++ b/test/cpp/microbenchmarks/bm_cq.cc @@ -69,11 +69,6 @@ BENCHMARK(BM_CreateDestroyCore); static void DoneWithCompletionOnStack(void* /*arg*/, grpc_cq_completion* /*completion*/) {} -static void DoneWithCompletionOnHeap(void* /*arg*/, - grpc_cq_completion* completion) { - delete completion; -} - class DummyTag final : public internal::CompletionQueueTag { public: bool FinalizeResult(void** /*tag*/, bool* /*status*/) override { @@ -210,15 +205,8 @@ static void BM_Callback_CQ_Pass1Core(benchmark::State& state) { gpr_cv_init(&shutdown_cv); bool got_shutdown = false; ShutdownCallback shutdown_cb(&got_shutdown); - // This test with stack-allocated completions only works for non-polling or - // EM-polling callback core CQs. For generality, test with non-polling. - grpc_completion_queue_attributes attr; - attr.version = 2; - attr.cq_completion_type = GRPC_CQ_CALLBACK; - attr.cq_polling_type = GRPC_CQ_NON_POLLING; - attr.cq_shutdown_cb = &shutdown_cb; - grpc_completion_queue* cc = grpc_completion_queue_create( - grpc_completion_queue_factory_lookup(&attr), &attr, nullptr); + grpc_completion_queue* cc = + grpc_completion_queue_create_for_callback(&shutdown_cb, nullptr); for (auto _ : state) { grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; grpc_core::ExecCtx exec_ctx; @@ -252,53 +240,7 @@ static void BM_Callback_CQ_Pass1Core(benchmark::State& state) { gpr_cv_destroy(&shutdown_cv); gpr_mu_destroy(&shutdown_mu); } -static void BM_Callback_CQ_Pass1CoreHeapCompletion(benchmark::State& state) { - TrackCounters track_counters; - int iteration = 0, current_iterations = 0; - TagCallback tag_cb(&iteration); - gpr_mu_init(&mu); - gpr_cv_init(&cv); - gpr_mu_init(&shutdown_mu); - gpr_cv_init(&shutdown_cv); - bool got_shutdown = false; - ShutdownCallback shutdown_cb(&got_shutdown); - grpc_completion_queue* cc = - grpc_completion_queue_create_for_callback(&shutdown_cb, nullptr); - for (auto _ : state) { - grpc_core::ApplicationCallbackExecCtx callback_exec_ctx; - grpc_core::ExecCtx exec_ctx; - grpc_cq_completion* completion = new grpc_cq_completion; - GPR_ASSERT(grpc_cq_begin_op(cc, &tag_cb)); - grpc_cq_end_op(cc, &tag_cb, GRPC_ERROR_NONE, DoneWithCompletionOnHeap, - nullptr, completion); - } - shutdown_and_destroy(cc); - - gpr_mu_lock(&mu); - current_iterations = static_cast(state.iterations()); - while (current_iterations != iteration) { - // Wait for all the callbacks to complete. - gpr_cv_wait(&cv, &mu, gpr_inf_future(GPR_CLOCK_REALTIME)); - } - gpr_mu_unlock(&mu); - - gpr_mu_lock(&shutdown_mu); - while (!got_shutdown) { - // Wait for the shutdown callback to complete. - gpr_cv_wait(&shutdown_cv, &shutdown_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); - } - gpr_mu_unlock(&shutdown_mu); - - GPR_ASSERT(got_shutdown); - GPR_ASSERT(iteration == static_cast(state.iterations())); - track_counters.Finish(state); - gpr_cv_destroy(&cv); - gpr_mu_destroy(&mu); - gpr_cv_destroy(&shutdown_cv); - gpr_mu_destroy(&shutdown_mu); -} BENCHMARK(BM_Callback_CQ_Pass1Core); -BENCHMARK(BM_Callback_CQ_Pass1CoreHeapCompletion); } // namespace testing } // namespace grpc From 52cde540a4768eea7a7a1ad0f21c99f6b51eedf7 Mon Sep 17 00:00:00 2001 From: Karthik Ravi Shankar Date: Tue, 28 Jul 2020 12:10:58 -0700 Subject: [PATCH 45/45] Revert "Uses sources.json from BoringSSL" --- src/boringssl/gen_build_yaml.py | 59 +++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/boringssl/gen_build_yaml.py b/src/boringssl/gen_build_yaml.py index eb4a59ae8b7..b54f53df095 100755 --- a/src/boringssl/gen_build_yaml.py +++ b/src/boringssl/gen_build_yaml.py @@ -13,16 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. -import json -import os +from __future__ import print_function +import shutil import sys +import os import yaml -sources_path = os.path.abspath( +sys.dont_write_bytecode = True + +boring_ssl_root = os.path.abspath( os.path.join(os.path.dirname(sys.argv[0]), - '../../third_party/boringssl-with-bazel/sources.json')) -with open(sources_path, 'r') as s: - sources = json.load(s) + '../../third_party/boringssl-with-bazel/src')) +sys.path.append(os.path.join(boring_ssl_root, 'util')) + +try: + import generate_build_files +except ImportError: + print(yaml.dump({})) + sys.exit() def map_dir(filename): @@ -30,19 +38,18 @@ def map_dir(filename): class Grpc(object): - """Adapter for boring-SSL json sources files. """ - - def __init__(self, sources): - self.yaml = None - self.WriteFiles(sources) + """Implements a "platform" in the sense of boringssl's generate_build_files.py""" + yaml = None - def WriteFiles(self, files): + def WriteFiles(self, files, asm_outputs): test_binaries = ['ssl_test', 'crypto_test'] + self.yaml = { '#': 'generated with src/boringssl/gen_build_yaml.py', 'raw_boringssl_build_output_for_debugging': { 'files': files, + 'asm_outputs': asm_outputs, }, 'libs': [ { @@ -113,5 +120,29 @@ class Grpc(object): } -grpc_platform = Grpc(sources) -print(yaml.dump(grpc_platform.yaml)) +os.chdir(os.path.dirname(sys.argv[0])) +os.mkdir('src') +try: + for f in os.listdir(boring_ssl_root): + os.symlink(os.path.join(boring_ssl_root, f), os.path.join('src', f)) + + grpc_platform = Grpc() + # We use a hack to run boringssl's util/generate_build_files.py as part of this script. + # The call will populate "grpc_platform" with boringssl's source file metadata. + # As a side effect this script generates err_data.c and crypto_test_data.cc (requires golang) + # Both of these files are already available under third_party/boringssl-with-bazel + # so we don't need to generate them again, but there's no option to disable that behavior. + # - crypto_test_data.cc is required to run boringssl_crypto_test but we already + # use the copy under third_party/boringssl-with-bazel so we just delete it + # - err_data.c is already under third_party/boringssl-with-bazel so we just delete it + generate_build_files.main([grpc_platform]) + + print(yaml.dump(grpc_platform.yaml)) + +finally: + # we don't want err_data.c and crypto_test_data.cc (see comment above) + if os.path.exists('err_data.c'): + os.remove('err_data.c') + if os.path.exists('crypto_test_data.cc'): + os.remove('crypto_test_data.cc') + shutil.rmtree('src')