From c35a37d6c27bf59096382f6a2d53ed49b8561b8b Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 22 Jul 2020 17:52:33 -0700 Subject: [PATCH] Remove TargetAuthorityTable in favor of a per-address channel arg. --- BUILD | 6 +- BUILD.gn | 6 +- CMakeLists.txt | 83 +------ Makefile | 100 +------- build_autogenerated.yaml | 38 +-- config.m4 | 2 +- config.w32 | 2 +- gRPC-C++.podspec | 8 +- gRPC-Core.podspec | 10 +- grpc.gemspec | 6 +- grpc.gyp | 3 +- package.xml | 6 +- .../client_channel/lb_policy/grpclb/grpclb.cc | 1 - .../grpclb/grpclb_balancer_addresses.cc | 13 - .../grpclb/grpclb_balancer_addresses.h | 3 - .../lb_policy/grpclb/grpclb_channel_secure.cc | 38 +-- .../resolver/dns/c_ares/grpc_ares_wrapper.cc | 4 +- .../client_channel/resolver_result_parsing.h | 1 - .../ext/filters/client_channel/subchannel.h | 2 +- .../client_channel/xds/xds_channel_secure.cc | 1 - .../filters/client_channel/xds/xds_client.cc | 1 - .../client/secure/secure_channel_create.cc | 45 +--- .../fake/fake_security_connector.cc | 1 - .../transport/target_authority_table.cc | 75 ------ .../transport/target_authority_table.h | 40 --- src/core/lib/slice/slice_hash_table.h | 199 --------------- src/core/lib/slice/slice_weak_hash_table.h | 102 -------- src/core/lib/transport/authority_override.cc | 38 +++ src/core/lib/transport/authority_override.h | 32 +++ src/python/grpcio/grpc_core_dependencies.py | 2 +- test/core/slice/BUILD | 30 --- test/core/slice/slice_hash_table_test.cc | 227 ------------------ test/core/slice/slice_weak_hash_table_test.cc | 107 --------- test/cpp/client/client_channel_stress_test.cc | 5 +- test/cpp/end2end/grpclb_end2end_test.cc | 5 +- tools/doxygen/Doxyfile.c++.internal | 6 +- tools/doxygen/Doxyfile.core.internal | 6 +- tools/run_tests/generated/tests.json | 48 ---- 38 files changed, 120 insertions(+), 1182 deletions(-) delete mode 100644 src/core/lib/security/transport/target_authority_table.cc delete mode 100644 src/core/lib/security/transport/target_authority_table.h delete mode 100644 src/core/lib/slice/slice_hash_table.h delete mode 100644 src/core/lib/slice/slice_weak_hash_table.h create mode 100644 src/core/lib/transport/authority_override.cc create mode 100644 src/core/lib/transport/authority_override.h delete mode 100644 test/core/slice/slice_hash_table_test.cc delete mode 100644 test/core/slice/slice_weak_hash_table_test.cc diff --git a/BUILD b/BUILD index b3c97ca5e2a..5c101f04a77 100644 --- a/BUILD +++ b/BUILD @@ -798,6 +798,7 @@ grpc_cc_library( "src/core/lib/surface/server.cc", "src/core/lib/surface/validate_metadata.cc", "src/core/lib/surface/version.cc", + "src/core/lib/transport/authority_override.cc", "src/core/lib/transport/bdp_estimator.cc", "src/core/lib/transport/byte_stream.cc", "src/core/lib/transport/connectivity_state.cc", @@ -919,11 +920,9 @@ grpc_cc_library( "src/core/lib/json/json.h", "src/core/lib/slice/b64.h", "src/core/lib/slice/percent_encoding.h", - "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_internal.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/slice/slice_utils.h", - "src/core/lib/slice/slice_weak_hash_table.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", "src/core/lib/surface/call_test_only.h", @@ -937,6 +936,7 @@ grpc_cc_library( "src/core/lib/surface/lame_client.h", "src/core/lib/surface/server.h", "src/core/lib/surface/validate_metadata.h", + "src/core/lib/transport/authority_override.h", "src/core/lib/transport/bdp_estimator.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", @@ -1806,7 +1806,6 @@ grpc_cc_library( "src/core/lib/security/transport/secure_endpoint.cc", "src/core/lib/security/transport/security_handshaker.cc", "src/core/lib/security/transport/server_auth_filter.cc", - "src/core/lib/security/transport/target_authority_table.cc", "src/core/lib/security/transport/tsi_error.cc", "src/core/lib/security/util/json_util.cc", "src/core/lib/surface/init_secure.cc", @@ -1843,7 +1842,6 @@ grpc_cc_library( "src/core/lib/security/transport/auth_filters.h", "src/core/lib/security/transport/secure_endpoint.h", "src/core/lib/security/transport/security_handshaker.h", - "src/core/lib/security/transport/target_authority_table.h", "src/core/lib/security/transport/tsi_error.h", "src/core/lib/security/util/json_util.h", ], diff --git a/BUILD.gn b/BUILD.gn index 035d6bddde6..4012ea8dfd5 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -846,8 +846,6 @@ config("grpc_config") { "src/core/lib/security/transport/security_handshaker.cc", "src/core/lib/security/transport/security_handshaker.h", "src/core/lib/security/transport/server_auth_filter.cc", - "src/core/lib/security/transport/target_authority_table.cc", - "src/core/lib/security/transport/target_authority_table.h", "src/core/lib/security/transport/tsi_error.cc", "src/core/lib/security/transport/tsi_error.h", "src/core/lib/security/util/json_util.cc", @@ -858,13 +856,11 @@ config("grpc_config") { "src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/slice.cc", "src/core/lib/slice/slice_buffer.cc", - "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_intern.cc", "src/core/lib/slice/slice_internal.h", "src/core/lib/slice/slice_string_helpers.cc", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/slice/slice_utils.h", - "src/core/lib/slice/slice_weak_hash_table.h", "src/core/lib/surface/api_trace.cc", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/byte_buffer.cc", @@ -898,6 +894,8 @@ config("grpc_config") { "src/core/lib/surface/validate_metadata.cc", "src/core/lib/surface/validate_metadata.h", "src/core/lib/surface/version.cc", + "src/core/lib/transport/authority_override.cc", + "src/core/lib/transport/authority_override.h", "src/core/lib/transport/bdp_estimator.cc", "src/core/lib/transport/bdp_estimator.h", "src/core/lib/transport/byte_stream.cc", diff --git a/CMakeLists.txt b/CMakeLists.txt index ce8a7e338c0..c4d4af0b6b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -809,8 +809,6 @@ if(gRPC_BUILD_TESTS) add_dependencies(buildtests_cxx settings_timeout_test) add_dependencies(buildtests_cxx shutdown_test) add_dependencies(buildtests_cxx simple_request_bad_client_test) - add_dependencies(buildtests_cxx slice_hash_table_test) - add_dependencies(buildtests_cxx slice_weak_hash_table_test) add_dependencies(buildtests_cxx static_metadata_test) add_dependencies(buildtests_cxx stats_test) add_dependencies(buildtests_cxx status_metadata_test) @@ -1678,7 +1676,6 @@ add_library(grpc src/core/lib/security/transport/secure_endpoint.cc src/core/lib/security/transport/security_handshaker.cc src/core/lib/security/transport/server_auth_filter.cc - src/core/lib/security/transport/target_authority_table.cc src/core/lib/security/transport/tsi_error.cc src/core/lib/security/util/json_util.cc src/core/lib/slice/b64.cc @@ -1707,6 +1704,7 @@ add_library(grpc src/core/lib/surface/server.cc src/core/lib/surface/validate_metadata.cc src/core/lib/surface/version.cc + src/core/lib/transport/authority_override.cc src/core/lib/transport/bdp_estimator.cc src/core/lib/transport/byte_stream.cc src/core/lib/transport/connectivity_state.cc @@ -2337,6 +2335,7 @@ add_library(grpc_unsecure src/core/lib/surface/server.cc src/core/lib/surface/validate_metadata.cc src/core/lib/surface/version.cc + src/core/lib/transport/authority_override.cc src/core/lib/transport/bdp_estimator.cc src/core/lib/transport/byte_stream.cc src/core/lib/transport/connectivity_state.cc @@ -13761,84 +13760,6 @@ target_link_libraries(simple_request_bad_client_test ) -endif() -if(gRPC_BUILD_TESTS) - -add_executable(slice_hash_table_test - test/core/slice/slice_hash_table_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - -target_include_directories(slice_hash_table_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_RE2_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} - third_party/googletest/googletest/include - third_party/googletest/googletest - third_party/googletest/googlemock/include - third_party/googletest/googlemock - ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(slice_hash_table_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr - address_sorting - upb - ${_gRPC_GFLAGS_LIBRARIES} -) - - -endif() -if(gRPC_BUILD_TESTS) - -add_executable(slice_weak_hash_table_test - test/core/slice/slice_weak_hash_table_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - -target_include_directories(slice_weak_hash_table_test - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - ${_gRPC_RE2_INCLUDE_DIR} - ${_gRPC_SSL_INCLUDE_DIR} - ${_gRPC_UPB_GENERATED_DIR} - ${_gRPC_UPB_GRPC_GENERATED_DIR} - ${_gRPC_UPB_INCLUDE_DIR} - ${_gRPC_ZLIB_INCLUDE_DIR} - third_party/googletest/googletest/include - third_party/googletest/googletest - third_party/googletest/googlemock/include - third_party/googletest/googlemock - ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(slice_weak_hash_table_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc_test_util - grpc - gpr - address_sorting - upb - ${_gRPC_GFLAGS_LIBRARIES} -) - - endif() if(gRPC_BUILD_TESTS) diff --git a/Makefile b/Makefile index b86df824e22..a1632e52831 100644 --- a/Makefile +++ b/Makefile @@ -1273,8 +1273,6 @@ service_config_test: $(BINDIR)/$(CONFIG)/service_config_test settings_timeout_test: $(BINDIR)/$(CONFIG)/settings_timeout_test shutdown_test: $(BINDIR)/$(CONFIG)/shutdown_test simple_request_bad_client_test: $(BINDIR)/$(CONFIG)/simple_request_bad_client_test -slice_hash_table_test: $(BINDIR)/$(CONFIG)/slice_hash_table_test -slice_weak_hash_table_test: $(BINDIR)/$(CONFIG)/slice_weak_hash_table_test ssl_server_fuzzer: $(BINDIR)/$(CONFIG)/ssl_server_fuzzer static_metadata_test: $(BINDIR)/$(CONFIG)/static_metadata_test stats_test: $(BINDIR)/$(CONFIG)/stats_test @@ -1635,8 +1633,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/settings_timeout_test \ $(BINDIR)/$(CONFIG)/shutdown_test \ $(BINDIR)/$(CONFIG)/simple_request_bad_client_test \ - $(BINDIR)/$(CONFIG)/slice_hash_table_test \ - $(BINDIR)/$(CONFIG)/slice_weak_hash_table_test \ $(BINDIR)/$(CONFIG)/static_metadata_test \ $(BINDIR)/$(CONFIG)/stats_test \ $(BINDIR)/$(CONFIG)/status_metadata_test \ @@ -1794,8 +1790,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/settings_timeout_test \ $(BINDIR)/$(CONFIG)/shutdown_test \ $(BINDIR)/$(CONFIG)/simple_request_bad_client_test \ - $(BINDIR)/$(CONFIG)/slice_hash_table_test \ - $(BINDIR)/$(CONFIG)/slice_weak_hash_table_test \ $(BINDIR)/$(CONFIG)/static_metadata_test \ $(BINDIR)/$(CONFIG)/stats_test \ $(BINDIR)/$(CONFIG)/status_metadata_test \ @@ -2314,10 +2308,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/shutdown_test || ( echo test shutdown_test failed ; exit 1 ) $(E) "[RUN] Testing simple_request_bad_client_test" $(Q) $(BINDIR)/$(CONFIG)/simple_request_bad_client_test || ( echo test simple_request_bad_client_test failed ; exit 1 ) - $(E) "[RUN] Testing slice_hash_table_test" - $(Q) $(BINDIR)/$(CONFIG)/slice_hash_table_test || ( echo test slice_hash_table_test failed ; exit 1 ) - $(E) "[RUN] Testing slice_weak_hash_table_test" - $(Q) $(BINDIR)/$(CONFIG)/slice_weak_hash_table_test || ( echo test slice_weak_hash_table_test failed ; exit 1 ) $(E) "[RUN] Testing static_metadata_test" $(Q) $(BINDIR)/$(CONFIG)/static_metadata_test || ( echo test static_metadata_test failed ; exit 1 ) $(E) "[RUN] Testing stats_test" @@ -3746,7 +3736,6 @@ LIBGRPC_SRC = \ src/core/lib/security/transport/secure_endpoint.cc \ src/core/lib/security/transport/security_handshaker.cc \ src/core/lib/security/transport/server_auth_filter.cc \ - src/core/lib/security/transport/target_authority_table.cc \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/slice/b64.cc \ @@ -3775,6 +3764,7 @@ LIBGRPC_SRC = \ src/core/lib/surface/server.cc \ src/core/lib/surface/validate_metadata.cc \ src/core/lib/surface/version.cc \ + src/core/lib/transport/authority_override.cc \ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/byte_stream.cc \ src/core/lib/transport/connectivity_state.cc \ @@ -4374,6 +4364,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/server.cc \ src/core/lib/surface/validate_metadata.cc \ src/core/lib/surface/version.cc \ + src/core/lib/transport/authority_override.cc \ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/byte_stream.cc \ src/core/lib/transport/connectivity_state.cc \ @@ -17621,92 +17612,6 @@ endif endif -SLICE_HASH_TABLE_TEST_SRC = \ - test/core/slice/slice_hash_table_test.cc \ - -SLICE_HASH_TABLE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SLICE_HASH_TABLE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/slice_hash_table_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.12.0+. - -$(BINDIR)/$(CONFIG)/slice_hash_table_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/slice_hash_table_test: $(PROTOBUF_DEP) $(SLICE_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(SLICE_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/slice_hash_table_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/slice/slice_hash_table_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a - -deps_slice_hash_table_test: $(SLICE_HASH_TABLE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(SLICE_HASH_TABLE_TEST_OBJS:.o=.dep) -endif -endif - - -SLICE_WEAK_HASH_TABLE_TEST_SRC = \ - test/core/slice/slice_weak_hash_table_test.cc \ - -SLICE_WEAK_HASH_TABLE_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(SLICE_WEAK_HASH_TABLE_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/slice_weak_hash_table_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.12.0+. - -$(BINDIR)/$(CONFIG)/slice_weak_hash_table_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/slice_weak_hash_table_test: $(PROTOBUF_DEP) $(SLICE_WEAK_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(SLICE_WEAK_HASH_TABLE_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/slice_weak_hash_table_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/core/slice/slice_weak_hash_table_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libaddress_sorting.a $(LIBDIR)/$(CONFIG)/libupb.a - -deps_slice_weak_hash_table_test: $(SLICE_WEAK_HASH_TABLE_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(SLICE_WEAK_HASH_TABLE_TEST_OBJS:.o=.dep) -endif -endif - - SSL_SERVER_FUZZER_SRC = \ test/core/security/ssl_server_fuzzer.cc \ test/core/util/fuzzer_corpus_test.cc \ @@ -19948,7 +19853,6 @@ src/core/lib/security/transport/client_auth_filter.cc: $(OPENSSL_DEP) src/core/lib/security/transport/secure_endpoint.cc: $(OPENSSL_DEP) src/core/lib/security/transport/security_handshaker.cc: $(OPENSSL_DEP) src/core/lib/security/transport/server_auth_filter.cc: $(OPENSSL_DEP) -src/core/lib/security/transport/target_authority_table.cc: $(OPENSSL_DEP) src/core/lib/security/transport/tsi_error.cc: $(OPENSSL_DEP) src/core/lib/security/util/json_util.cc: $(OPENSSL_DEP) src/core/lib/surface/init_secure.cc: $(OPENSSL_DEP) diff --git a/build_autogenerated.yaml b/build_autogenerated.yaml index 23a3e3c0554..c69992f7c17 100644 --- a/build_autogenerated.yaml +++ b/build_autogenerated.yaml @@ -673,16 +673,13 @@ libs: - src/core/lib/security/transport/auth_filters.h - src/core/lib/security/transport/secure_endpoint.h - src/core/lib/security/transport/security_handshaker.h - - src/core/lib/security/transport/target_authority_table.h - src/core/lib/security/transport/tsi_error.h - src/core/lib/security/util/json_util.h - src/core/lib/slice/b64.h - src/core/lib/slice/percent_encoding.h - - src/core/lib/slice/slice_hash_table.h - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_string_helpers.h - src/core/lib/slice/slice_utils.h - - src/core/lib/slice/slice_weak_hash_table.h - src/core/lib/surface/api_trace.h - src/core/lib/surface/call.h - src/core/lib/surface/call_test_only.h @@ -696,6 +693,7 @@ libs: - src/core/lib/surface/lame_client.h - src/core/lib/surface/server.h - src/core/lib/surface/validate_metadata.h + - src/core/lib/transport/authority_override.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h @@ -1086,7 +1084,6 @@ libs: - src/core/lib/security/transport/secure_endpoint.cc - src/core/lib/security/transport/security_handshaker.cc - src/core/lib/security/transport/server_auth_filter.cc - - src/core/lib/security/transport/target_authority_table.cc - src/core/lib/security/transport/tsi_error.cc - src/core/lib/security/util/json_util.cc - src/core/lib/slice/b64.cc @@ -1115,6 +1112,7 @@ libs: - src/core/lib/surface/server.cc - src/core/lib/surface/validate_metadata.cc - src/core/lib/surface/version.cc + - src/core/lib/transport/authority_override.cc - src/core/lib/transport/bdp_estimator.cc - src/core/lib/transport/byte_stream.cc - src/core/lib/transport/connectivity_state.cc @@ -1569,11 +1567,9 @@ libs: - src/core/lib/json/json.h - src/core/lib/slice/b64.h - src/core/lib/slice/percent_encoding.h - - src/core/lib/slice/slice_hash_table.h - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_string_helpers.h - src/core/lib/slice/slice_utils.h - - src/core/lib/slice/slice_weak_hash_table.h - src/core/lib/surface/api_trace.h - src/core/lib/surface/call.h - src/core/lib/surface/call_test_only.h @@ -1587,6 +1583,7 @@ libs: - src/core/lib/surface/lame_client.h - src/core/lib/surface/server.h - src/core/lib/surface/validate_metadata.h + - src/core/lib/transport/authority_override.h - src/core/lib/transport/bdp_estimator.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h @@ -1931,6 +1928,7 @@ libs: - src/core/lib/surface/server.cc - src/core/lib/surface/validate_metadata.cc - src/core/lib/surface/version.cc + - src/core/lib/transport/authority_override.cc - src/core/lib/transport/bdp_estimator.cc - src/core/lib/transport/byte_stream.cc - src/core/lib/transport/connectivity_state.cc @@ -7123,34 +7121,6 @@ targets: - gpr - address_sorting - upb -- name: slice_hash_table_test - gtest: true - build: test - language: c++ - headers: [] - src: - - test/core/slice/slice_hash_table_test.cc - deps: - - grpc_test_util - - grpc - - gpr - - address_sorting - - upb - uses_polling: false -- name: slice_weak_hash_table_test - gtest: true - build: test - language: c++ - headers: [] - src: - - test/core/slice/slice_weak_hash_table_test.cc - deps: - - grpc_test_util - - grpc - - gpr - - address_sorting - - upb - uses_polling: false - name: ssl_server_fuzzer build: fuzzer language: c++ diff --git a/config.m4 b/config.m4 index 8cf43fc8a52..fd2b5007549 100644 --- a/config.m4 +++ b/config.m4 @@ -426,7 +426,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/security/transport/secure_endpoint.cc \ src/core/lib/security/transport/security_handshaker.cc \ src/core/lib/security/transport/server_auth_filter.cc \ - src/core/lib/security/transport/target_authority_table.cc \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/util/json_util.cc \ src/core/lib/slice/b64.cc \ @@ -455,6 +454,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/server.cc \ src/core/lib/surface/validate_metadata.cc \ src/core/lib/surface/version.cc \ + src/core/lib/transport/authority_override.cc \ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/byte_stream.cc \ src/core/lib/transport/connectivity_state.cc \ diff --git a/config.w32 b/config.w32 index 8f027adf682..25357651d7c 100644 --- a/config.w32 +++ b/config.w32 @@ -394,7 +394,6 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\security\\transport\\secure_endpoint.cc " + "src\\core\\lib\\security\\transport\\security_handshaker.cc " + "src\\core\\lib\\security\\transport\\server_auth_filter.cc " + - "src\\core\\lib\\security\\transport\\target_authority_table.cc " + "src\\core\\lib\\security\\transport\\tsi_error.cc " + "src\\core\\lib\\security\\util\\json_util.cc " + "src\\core\\lib\\slice\\b64.cc " + @@ -423,6 +422,7 @@ if (PHP_GRPC != "no") { "src\\core\\lib\\surface\\server.cc " + "src\\core\\lib\\surface\\validate_metadata.cc " + "src\\core\\lib\\surface\\version.cc " + + "src\\core\\lib\\transport\\authority_override.cc " + "src\\core\\lib\\transport\\bdp_estimator.cc " + "src\\core\\lib\\transport\\byte_stream.cc " + "src\\core\\lib\\transport\\connectivity_state.cc " + diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index a0844acf9a9..1f40b5b3975 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -544,16 +544,13 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', 'src/core/lib/security/transport/security_handshaker.h', - 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', 'src/core/lib/slice/b64.h', 'src/core/lib/slice/percent_encoding.h', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_utils.h', - 'src/core/lib/slice/slice_weak_hash_table.h', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/call.h', 'src/core/lib/surface/call_test_only.h', @@ -567,6 +564,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', 'src/core/lib/surface/validate_metadata.h', + 'src/core/lib/transport/authority_override.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', @@ -1031,16 +1029,13 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', 'src/core/lib/security/transport/security_handshaker.h', - 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', 'src/core/lib/slice/b64.h', 'src/core/lib/slice/percent_encoding.h', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_utils.h', - 'src/core/lib/slice/slice_weak_hash_table.h', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/call.h', 'src/core/lib/surface/call_test_only.h', @@ -1054,6 +1049,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', 'src/core/lib/surface/validate_metadata.h', + 'src/core/lib/transport/authority_override.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 9ac673e2c3d..3080468b51c 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -899,8 +899,6 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/security_handshaker.cc', 'src/core/lib/security/transport/security_handshaker.h', 'src/core/lib/security/transport/server_auth_filter.cc', - 'src/core/lib/security/transport/target_authority_table.cc', - 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.cc', @@ -911,13 +909,11 @@ Pod::Spec.new do |s| 'src/core/lib/slice/percent_encoding.h', 'src/core/lib/slice/slice.cc', 'src/core/lib/slice/slice_buffer.cc', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_intern.cc', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.cc', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_utils.h', - 'src/core/lib/slice/slice_weak_hash_table.h', 'src/core/lib/surface/api_trace.cc', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/byte_buffer.cc', @@ -951,6 +947,8 @@ Pod::Spec.new do |s| 'src/core/lib/surface/validate_metadata.cc', 'src/core/lib/surface/validate_metadata.h', 'src/core/lib/surface/version.cc', + 'src/core/lib/transport/authority_override.cc', + 'src/core/lib/transport/authority_override.h', 'src/core/lib/transport/bdp_estimator.cc', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/byte_stream.cc', @@ -1427,16 +1425,13 @@ Pod::Spec.new do |s| 'src/core/lib/security/transport/auth_filters.h', 'src/core/lib/security/transport/secure_endpoint.h', 'src/core/lib/security/transport/security_handshaker.h', - 'src/core/lib/security/transport/target_authority_table.h', 'src/core/lib/security/transport/tsi_error.h', 'src/core/lib/security/util/json_util.h', 'src/core/lib/slice/b64.h', 'src/core/lib/slice/percent_encoding.h', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/slice/slice_utils.h', - 'src/core/lib/slice/slice_weak_hash_table.h', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/call.h', 'src/core/lib/surface/call_test_only.h', @@ -1450,6 +1445,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', 'src/core/lib/surface/validate_metadata.h', + 'src/core/lib/transport/authority_override.h', 'src/core/lib/transport/bdp_estimator.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', diff --git a/grpc.gemspec b/grpc.gemspec index 5b84d4ecf26..0412ddb88f5 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -821,8 +821,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/security/transport/security_handshaker.cc ) s.files += %w( src/core/lib/security/transport/security_handshaker.h ) s.files += %w( src/core/lib/security/transport/server_auth_filter.cc ) - s.files += %w( src/core/lib/security/transport/target_authority_table.cc ) - s.files += %w( src/core/lib/security/transport/target_authority_table.h ) s.files += %w( src/core/lib/security/transport/tsi_error.cc ) s.files += %w( src/core/lib/security/transport/tsi_error.h ) s.files += %w( src/core/lib/security/util/json_util.cc ) @@ -833,13 +831,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/slice/percent_encoding.h ) s.files += %w( src/core/lib/slice/slice.cc ) s.files += %w( src/core/lib/slice/slice_buffer.cc ) - s.files += %w( src/core/lib/slice/slice_hash_table.h ) s.files += %w( src/core/lib/slice/slice_intern.cc ) s.files += %w( src/core/lib/slice/slice_internal.h ) s.files += %w( src/core/lib/slice/slice_string_helpers.cc ) s.files += %w( src/core/lib/slice/slice_string_helpers.h ) s.files += %w( src/core/lib/slice/slice_utils.h ) - s.files += %w( src/core/lib/slice/slice_weak_hash_table.h ) s.files += %w( src/core/lib/surface/api_trace.cc ) s.files += %w( src/core/lib/surface/api_trace.h ) s.files += %w( src/core/lib/surface/byte_buffer.cc ) @@ -873,6 +869,8 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/validate_metadata.cc ) s.files += %w( src/core/lib/surface/validate_metadata.h ) s.files += %w( src/core/lib/surface/version.cc ) + s.files += %w( src/core/lib/transport/authority_override.cc ) + s.files += %w( src/core/lib/transport/authority_override.h ) s.files += %w( src/core/lib/transport/bdp_estimator.cc ) s.files += %w( src/core/lib/transport/bdp_estimator.h ) s.files += %w( src/core/lib/transport/byte_stream.cc ) diff --git a/grpc.gyp b/grpc.gyp index a7cae5e3f8b..7d157a697c1 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -782,7 +782,6 @@ 'src/core/lib/security/transport/secure_endpoint.cc', 'src/core/lib/security/transport/security_handshaker.cc', 'src/core/lib/security/transport/server_auth_filter.cc', - 'src/core/lib/security/transport/target_authority_table.cc', 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/slice/b64.cc', @@ -811,6 +810,7 @@ 'src/core/lib/surface/server.cc', 'src/core/lib/surface/validate_metadata.cc', 'src/core/lib/surface/version.cc', + 'src/core/lib/transport/authority_override.cc', 'src/core/lib/transport/bdp_estimator.cc', 'src/core/lib/transport/byte_stream.cc', 'src/core/lib/transport/connectivity_state.cc', @@ -1272,6 +1272,7 @@ 'src/core/lib/surface/server.cc', 'src/core/lib/surface/validate_metadata.cc', 'src/core/lib/surface/version.cc', + 'src/core/lib/transport/authority_override.cc', 'src/core/lib/transport/bdp_estimator.cc', 'src/core/lib/transport/byte_stream.cc', 'src/core/lib/transport/connectivity_state.cc', diff --git a/package.xml b/package.xml index 36399edc3e1..5cd2bcfb60c 100644 --- a/package.xml +++ b/package.xml @@ -801,8 +801,6 @@ - - @@ -813,13 +811,11 @@ - - @@ -853,6 +849,8 @@ + + diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc index e4248a6f556..e9216a11920 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc @@ -101,7 +101,6 @@ #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/call.h" diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc index 2888c3b94ae..0bd587a9323 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc @@ -23,8 +23,6 @@ // Channel arg key for the list of balancer addresses. #define GRPC_ARG_GRPCLB_BALANCER_ADDRESSES "grpc.grpclb_balancer_addresses" -// Channel arg key for a string indicating an address's balancer name. -#define GRPC_ARG_ADDRESS_BALANCER_NAME "grpc.address_balancer_name" namespace grpc_core { @@ -75,15 +73,4 @@ const ServerAddressList* FindGrpclbBalancerAddressesInChannelArgs( &args, const_cast(GRPC_ARG_GRPCLB_BALANCER_ADDRESSES)); } -grpc_arg CreateGrpclbBalancerNameArg(const char* balancer_name) { - return grpc_channel_arg_string_create( - const_cast(GRPC_ARG_ADDRESS_BALANCER_NAME), - const_cast(balancer_name)); -} - -const char* FindGrpclbBalancerNameInChannelArgs(const grpc_channel_args& args) { - return grpc_channel_args_find_string( - &args, const_cast(GRPC_ARG_ADDRESS_BALANCER_NAME)); -} - } // namespace grpc_core diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h index 9b6b259deca..f95341e3f40 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h @@ -30,9 +30,6 @@ grpc_arg CreateGrpclbBalancerAddressesArg( const ServerAddressList* FindGrpclbBalancerAddressesInChannelArgs( const grpc_channel_args& args); -grpc_arg CreateGrpclbBalancerNameArg(const char* balancer_name); -const char* FindGrpclbBalancerNameInChannelArgs(const grpc_channel_args& args); - } // namespace grpc_core #endif /* \ diff --git a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc index ab179d30d7d..62fbe15b27a 100644 --- a/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +++ b/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc @@ -35,50 +35,14 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/security/credentials/credentials.h" -#include "src/core/lib/security/transport/target_authority_table.h" #include "src/core/lib/slice/slice_internal.h" namespace grpc_core { -namespace { - -int BalancerNameCmp(const grpc_core::UniquePtr& a, - const grpc_core::UniquePtr& b) { - return strcmp(a.get(), b.get()); -} - -RefCountedPtr CreateTargetAuthorityTable( - const ServerAddressList& addresses) { - TargetAuthorityTable::Entry* target_authority_entries = - static_cast( - gpr_zalloc(sizeof(*target_authority_entries) * addresses.size())); - for (size_t i = 0; i < addresses.size(); ++i) { - std::string addr_str = - grpc_sockaddr_to_string(&addresses[i].address(), true); - target_authority_entries[i].key = - grpc_slice_from_copied_string(addr_str.c_str()); - const char* balancer_name = - FindGrpclbBalancerNameInChannelArgs(*addresses[i].args()); - target_authority_entries[i].value.reset(gpr_strdup(balancer_name)); - } - RefCountedPtr target_authority_table = - TargetAuthorityTable::Create(addresses.size(), target_authority_entries, - BalancerNameCmp); - gpr_free(target_authority_entries); - return target_authority_table; -} - -} // namespace - grpc_channel_args* ModifyGrpclbBalancerChannelArgs( const ServerAddressList& addresses, grpc_channel_args* args) { absl::InlinedVector args_to_remove; - absl::InlinedVector args_to_add; - // Add arg for targets info table. - RefCountedPtr target_authority_table = - CreateTargetAuthorityTable(addresses); - args_to_add.emplace_back( - CreateTargetAuthorityTableChannelArg(target_authority_table.get())); + absl::InlinedVector args_to_add; // Substitute the channel credentials with a version without call // credentials: the load balancer is not necessarily trusted to handle // bearer token credentials. diff --git a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc index 05f78623eee..4951ff1a5e4 100644 --- a/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +++ b/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc @@ -37,7 +37,6 @@ #include #include -#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h" #include "src/core/ext/filters/client_channel/parse_address.h" #include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h" #include "src/core/lib/gpr/string.h" @@ -47,6 +46,7 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/iomgr/nameser.h" #include "src/core/lib/iomgr/sockaddr_utils.h" +#include "src/core/lib/transport/authority_override.h" using grpc_core::ServerAddress; using grpc_core::ServerAddressList; @@ -237,7 +237,7 @@ static void on_hostbyname_done_locked(void* arg, int status, int /*timeouts*/, absl::InlinedVector args_to_add; if (hr->is_balancer) { args_to_add.emplace_back( - grpc_core::CreateGrpclbBalancerNameArg(hr->host)); + grpc_core::CreateAuthorityOverrideChannelArg(hr->host)); } grpc_channel_args* args = grpc_channel_args_copy_and_add( nullptr, args_to_add.data(), args_to_add.size()); diff --git a/src/core/ext/filters/client_channel/resolver_result_parsing.h b/src/core/ext/filters/client_channel/resolver_result_parsing.h index 7e85868aa04..2f0c0a2cb9f 100644 --- a/src/core/ext/filters/client_channel/resolver_result_parsing.h +++ b/src/core/ext/filters/client_channel/resolver_result_parsing.h @@ -33,7 +33,6 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/exec_ctx.h" // for grpc_millis #include "src/core/lib/json/json.h" -#include "src/core/lib/slice/slice_hash_table.h" namespace grpc_core { namespace internal { diff --git a/src/core/ext/filters/client_channel/subchannel.h b/src/core/ext/filters/client_channel/subchannel.h index 9478fa7340c..7c1afcd515f 100644 --- a/src/core/ext/filters/client_channel/subchannel.h +++ b/src/core/ext/filters/client_channel/subchannel.h @@ -39,7 +39,7 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata.h" -// Channel arg containing a grpc_resolved_address to connect to. +// Channel arg containing a URI indicating the address to connect to. #define GRPC_ARG_SUBCHANNEL_ADDRESS "grpc.subchannel_address" // For debugging refcounting. diff --git a/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc b/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc index 9252e553cee..859126c6109 100644 --- a/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +++ b/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc @@ -35,7 +35,6 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" -#include "src/core/lib/security/transport/target_authority_table.h" #include "src/core/lib/slice/slice_internal.h" namespace grpc_core { diff --git a/src/core/ext/filters/client_channel/xds/xds_client.cc b/src/core/ext/filters/client_channel/xds/xds_client.cc index 3010c6b23d0..cb35f69e99d 100644 --- a/src/core/ext/filters/client_channel/xds/xds_client.cc +++ b/src/core/ext/filters/client_channel/xds/xds_client.cc @@ -54,7 +54,6 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/iomgr/work_serializer.h" -#include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/call.h" diff --git a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc index 33aa0cd0808..93dadf36456 100644 --- a/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +++ b/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc @@ -33,11 +33,10 @@ #include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/security_connector/security_connector.h" -#include "src/core/lib/security/transport/target_authority_table.h" -#include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/channel.h" +#include "src/core/lib/transport/authority_override.h" #include "src/core/lib/uri/uri_parser.h" namespace grpc_core { @@ -75,39 +74,16 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory { "channel args."); return nullptr; } - // To which address are we connecting? By default, use the server URI. - const grpc_arg* server_uri_arg = - grpc_channel_args_find(args, GRPC_ARG_SERVER_URI); - const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg); - GPR_ASSERT(server_uri_str != nullptr); - grpc_uri* server_uri = - grpc_uri_parse(server_uri_str, true /* suppress errors */); - GPR_ASSERT(server_uri != nullptr); - const TargetAuthorityTable* target_authority_table = - FindTargetAuthorityTableInArgs(args); - grpc_core::UniquePtr authority; - if (target_authority_table != nullptr) { - // Find the authority for the target. - const char* target_uri_str = - Subchannel::GetUriFromSubchannelAddressArg(args); - grpc_uri* target_uri = - grpc_uri_parse(target_uri_str, false /* suppress errors */); - GPR_ASSERT(target_uri != nullptr); - if (target_uri->path[0] != '\0') { // "path" may be empty - const grpc_slice key = grpc_slice_from_static_string( - target_uri->path[0] == '/' ? target_uri->path + 1 - : target_uri->path); - const grpc_core::UniquePtr* value = - target_authority_table->Get(key); - if (value != nullptr) authority.reset(gpr_strdup(value->get())); - grpc_slice_unref_internal(key); - } - grpc_uri_destroy(target_uri); - } - // If the authority hasn't already been set (either because no target - // authority table was present or because the target was not present - // in the table), fall back to using the original server URI. + // Find the authority to use in the security connector. + // First, check the authority override channel arg. + // Otherwise, get it from the server name used to construct the + // channel. + grpc_core::UniquePtr authority( + gpr_strdup(FindAuthorityOverrideInArgs(args))); if (authority == nullptr) { + const char* server_uri_str = + grpc_channel_args_find_string(args, GRPC_ARG_SERVER_URI); + GPR_ASSERT(server_uri_str != nullptr); authority = ResolverRegistry::GetDefaultAuthority(server_uri_str); } grpc_arg args_to_add[2]; @@ -120,7 +96,6 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory { } grpc_channel_args* args_with_authority = grpc_channel_args_copy_and_add(args, args_to_add, num_args_to_add); - grpc_uri_destroy(server_uri); // Create the security connector using the credentials and target name. grpc_channel_args* new_args_from_connector = nullptr; RefCountedPtr diff --git a/src/core/lib/security/security_connector/fake/fake_security_connector.cc b/src/core/lib/security/security_connector/fake/fake_security_connector.cc index 48ac99d7a50..2908c7f3754 100644 --- a/src/core/lib/security/security_connector/fake/fake_security_connector.cc +++ b/src/core/lib/security/security_connector/fake/fake_security_connector.cc @@ -40,7 +40,6 @@ #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" #include "src/core/lib/security/transport/security_handshaker.h" -#include "src/core/lib/security/transport/target_authority_table.h" #include "src/core/tsi/fake_transport_security.h" namespace { diff --git a/src/core/lib/security/transport/target_authority_table.cc b/src/core/lib/security/transport/target_authority_table.cc deleted file mode 100644 index 1eeb557f6a4..00000000000 --- a/src/core/lib/security/transport/target_authority_table.cc +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Copyright 2017 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 - -#include - -#include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/security/transport/target_authority_table.h" - -// Channel arg key for the mapping of target addresses to their authorities. -#define GRPC_ARG_TARGET_AUTHORITY_TABLE "grpc.target_authority_table" - -namespace grpc_core { -namespace { - -void* target_authority_table_copy(void* p) { - TargetAuthorityTable* table = static_cast(p); - // TODO(roth): When channel_args are converted to C++, pass the - // RefCountedPtr<> directly instead of managing the ref manually. - table->Ref().release(); - return p; -} -void target_authority_table_destroy(void* p) { - TargetAuthorityTable* table = static_cast(p); - table->Unref(); -} -int target_authority_table_cmp(void* a, void* b) { - return TargetAuthorityTable::Cmp( - *static_cast(a), - *static_cast(b)); -} -const grpc_arg_pointer_vtable target_authority_table_arg_vtable = { - target_authority_table_copy, target_authority_table_destroy, - target_authority_table_cmp}; - -} // namespace - -grpc_arg CreateTargetAuthorityTableChannelArg(TargetAuthorityTable* table) { - return grpc_channel_arg_pointer_create((char*)GRPC_ARG_TARGET_AUTHORITY_TABLE, - table, - &target_authority_table_arg_vtable); -} - -TargetAuthorityTable* FindTargetAuthorityTableInArgs( - const grpc_channel_args* args) { - const grpc_arg* arg = - grpc_channel_args_find(args, GRPC_ARG_TARGET_AUTHORITY_TABLE); - if (arg != nullptr) { - if (arg->type == GRPC_ARG_POINTER) { - return static_cast(arg->value.pointer.p); - } else { - gpr_log(GPR_ERROR, "value of " GRPC_ARG_TARGET_AUTHORITY_TABLE - " channel arg was not pointer type; ignoring"); - } - } - return nullptr; -} - -} // namespace grpc_core diff --git a/src/core/lib/security/transport/target_authority_table.h b/src/core/lib/security/transport/target_authority_table.h deleted file mode 100644 index 10ed66fbab3..00000000000 --- a/src/core/lib/security/transport/target_authority_table.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Copyright 2017 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 GRPC_CORE_LIB_SECURITY_TRANSPORT_TARGET_AUTHORITY_TABLE_H -#define GRPC_CORE_LIB_SECURITY_TRANSPORT_TARGET_AUTHORITY_TABLE_H - -#include - -#include "src/core/lib/slice/slice_hash_table.h" - -namespace grpc_core { - -/// A hash table mapping target addresses to authorities. -typedef SliceHashTable> TargetAuthorityTable; - -/// Returns a channel argument containing \a table. -grpc_arg CreateTargetAuthorityTableChannelArg(TargetAuthorityTable* table); - -/// Returns the target authority table from \a args or nullptr. -TargetAuthorityTable* FindTargetAuthorityTableInArgs( - const grpc_channel_args* args); - -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_SECURITY_TRANSPORT_TARGET_AUTHORITY_TABLE_H */ diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h deleted file mode 100644 index 29a5fc6dd24..00000000000 --- a/src/core/lib/slice/slice_hash_table.h +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright 2016 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 GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H -#define GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H - -#include - -#include - -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/gprpp/ref_counted.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" -#include "src/core/lib/slice/slice_internal.h" - -/// Hash table implementation. -/// -/// This implementation uses open addressing -/// (https://en.wikipedia.org/wiki/Open_addressing) with linear -/// probing (https://en.wikipedia.org/wiki/Linear_probing). -/// -/// The keys are \a grpc_slice objects. The values can be any type. -/// -/// Hash tables are intentionally immutable, to avoid the need for locking. - -namespace grpc_core { - -template -class SliceHashTable : public RefCounted> { - public: - struct Entry { - grpc_slice key; - T value; - bool is_set; - }; - - // Function for comparing values. - // TODO(roth): Eliminate this and the Cmp() method from this API once - // grpc_channel_args is redesigned to require that keys are unique. - typedef int (*ValueCmp)(const T&, const T&); - - /// Creates a new hash table containing \a entries, which is an array - /// of length \a num_entries. Takes ownership of all keys and values in \a - /// entries. If not null, \a value_cmp will be used to compare values in - /// the context of \a Cmp(). If null, raw pointer (\a GPR_ICMP) comparison - /// will be used. - static RefCountedPtr Create(size_t num_entries, - Entry* entries, - ValueCmp value_cmp); - - // Use Create function instead of using this directly. - SliceHashTable(size_t num_entries, Entry* entries, ValueCmp value_cmp); - virtual ~SliceHashTable(); - - /// Returns the value from the table associated with \a key. - /// Returns null if \a key is not found. - const T* Get(const grpc_slice& key) const; - - /// Compares \a a vs. \a b. - /// A table is considered "smaller" (resp. "greater") if: - /// - GPR_ICMP(a->value_cmp, b->value_cmp) < 1 (resp. > 1), - /// - else, it contains fewer (resp. more) entries, - /// - else, if strcmp(a_key, b_key) < 1 (resp. > 1), - /// - else, if value_cmp(a_value, b_value) < 1 (resp. > 1). - static int Cmp(const SliceHashTable& a, const SliceHashTable& b); - - private: - void Add(const grpc_slice& key, T& value); - - // Default value comparison function, if none specified by caller. - static int DefaultValueCmp(const T& a, const T& b) { return GPR_ICMP(a, b); } - - const ValueCmp value_cmp_; - const size_t size_; - size_t max_num_probes_; - Entry* entries_; -}; - -// -// implementation -- no user-serviceable parts below -// - -template -RefCountedPtr> SliceHashTable::Create(size_t num_entries, - Entry* entries, - ValueCmp value_cmp) { - return MakeRefCounted>(num_entries, entries, value_cmp); -} - -template -SliceHashTable::SliceHashTable(size_t num_entries, Entry* entries, - ValueCmp value_cmp) - : value_cmp_(value_cmp), - // Keep load factor low to improve performance of lookups. - size_(num_entries * 2), - max_num_probes_(0) { - entries_ = static_cast(gpr_zalloc(sizeof(Entry) * size_)); - for (size_t i = 0; i < num_entries; ++i) { - Entry* entry = &entries[i]; - Add(entry->key, entry->value); - } -} - -template -SliceHashTable::~SliceHashTable() { - for (size_t i = 0; i < size_; ++i) { - Entry& entry = entries_[i]; - if (entry.is_set) { - grpc_slice_unref_internal(entry.key); - entry.value.~T(); - } - } - gpr_free(entries_); -} - -template -void SliceHashTable::Add(const grpc_slice& key, T& value) { - const size_t hash = grpc_slice_hash_internal(key); - for (size_t offset = 0; offset < size_; ++offset) { - const size_t idx = (hash + offset) % size_; - if (!entries_[idx].is_set) { - entries_[idx].is_set = true; - entries_[idx].key = key; - entries_[idx].value = std::move(value); - // Keep track of the maximum number of probes needed, since this - // provides an upper bound for lookups. - if (offset > max_num_probes_) max_num_probes_ = offset; - return; - } - } - GPR_ASSERT(false); // Table should never be full. -} - -template -const T* SliceHashTable::Get(const grpc_slice& key) const { - const size_t hash = grpc_slice_hash_internal(key); - // We cap the number of probes at the max number recorded when - // populating the table. - for (size_t offset = 0; offset <= max_num_probes_; ++offset) { - const size_t idx = (hash + offset) % size_; - if (!entries_[idx].is_set) break; - if (grpc_slice_eq(entries_[idx].key, key)) { - return &entries_[idx].value; - } - } - return nullptr; // Not found. -} - -template -int SliceHashTable::Cmp(const SliceHashTable& a, const SliceHashTable& b) { - ValueCmp value_cmp_a = - a.value_cmp_ != nullptr ? a.value_cmp_ : DefaultValueCmp; - ValueCmp value_cmp_b = - b.value_cmp_ != nullptr ? b.value_cmp_ : DefaultValueCmp; - // Compare value_fns - const int value_fns_cmp = GPR_ICMP((void*)value_cmp_a, (void*)value_cmp_b); - if (value_fns_cmp != 0) return value_fns_cmp; - // Compare sizes - if (a.size_ < b.size_) return -1; - if (a.size_ > b.size_) return 1; - // Compare rows. - for (size_t i = 0; i < a.size_; ++i) { - if (!a.entries_[i].is_set) { - if (b.entries_[i].is_set) { - return -1; // a empty but b non-empty - } - continue; // both empty, no need to check key or value - } else if (!b.entries_[i].is_set) { - return 1; // a non-empty but b empty - } - // neither entry is empty - const int key_cmp = grpc_slice_cmp(a.entries_[i].key, b.entries_[i].key); - if (key_cmp != 0) return key_cmp; - const int value_cmp = value_cmp_a(a.entries_[i].value, b.entries_[i].value); - if (value_cmp != 0) return value_cmp; - } - return 0; -} - -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H */ diff --git a/src/core/lib/slice/slice_weak_hash_table.h b/src/core/lib/slice/slice_weak_hash_table.h deleted file mode 100644 index 931e405c1e3..00000000000 --- a/src/core/lib/slice/slice_weak_hash_table.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2016 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 GRPC_CORE_LIB_SLICE_SLICE_WEAK_HASH_TABLE_H -#define GRPC_CORE_LIB_SLICE_SLICE_WEAK_HASH_TABLE_H - -#include - -#include "src/core/lib/gprpp/memory.h" -#include "src/core/lib/gprpp/ref_counted.h" -#include "src/core/lib/gprpp/ref_counted_ptr.h" -#include "src/core/lib/slice/slice_internal.h" - -/// Weak hash table implementation. -/// -/// This entries in this table are weak: an entry may be removed at any time due -/// to a number of reasons: memory pressure, hash collisions, etc. -/// -/// The keys are \a grpc_slice objects. The values are of arbitrary type. -/// -/// This class is thread unsafe. It's the caller's responsibility to ensure -/// proper locking when accessing its methods. - -namespace grpc_core { - -template -class SliceWeakHashTable : public RefCounted> { - public: - /// Creates a new table of at most \a size entries. - static RefCountedPtr Create() { - return MakeRefCounted>(); - } - - /// Use Create function instead of using this directly. - SliceWeakHashTable() = default; - ~SliceWeakHashTable() = default; - - /// Add a mapping from \a key to \a value, taking ownership of \a key. This - /// operation will always succeed. It may discard older entries. - void Add(const grpc_slice& key, T value) { - const size_t idx = grpc_slice_hash_internal(key) % Size; - entries_[idx].Set(key, std::move(value)); - return; - } - - /// Returns the value from the table associated with / \a key or null if not - /// found. - const T* Get(const grpc_slice& key) const { - const size_t idx = grpc_slice_hash_internal(key) % Size; - const auto& entry = entries_[idx]; - return grpc_slice_eq(entry.key(), key) ? entry.value() : nullptr; - } - - private: - /// The type of the table "rows". - class Entry { - public: - Entry() = default; - ~Entry() { - if (is_set_) grpc_slice_unref_internal(key_); - } - const grpc_slice& key() const { return key_; } - - /// Return the entry's value, or null if unset. - const T* value() const { - if (!is_set_) return nullptr; - return &value_; - } - - /// Set the \a key and \a value (which is moved) for the entry. - void Set(const grpc_slice& key, T&& value) { - if (is_set_) grpc_slice_unref_internal(key_); - key_ = key; - value_ = std::move(value); - is_set_ = true; - } - - private: - grpc_slice key_; - T value_; - bool is_set_ = false; - }; - - Entry entries_[Size]; -}; - -} // namespace grpc_core - -#endif /* GRPC_CORE_LIB_SLICE_SLICE_WEAK_HASH_TABLE_H */ diff --git a/src/core/lib/transport/authority_override.cc b/src/core/lib/transport/authority_override.cc new file mode 100644 index 00000000000..8c13320b73b --- /dev/null +++ b/src/core/lib/transport/authority_override.cc @@ -0,0 +1,38 @@ +// +// Copyright 2020 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 + +#include "src/core/lib/channel/channel_args.h" + +// Channel arg key for the authority override. +#define GRPC_ARG_AUTHORITY_OVERRIDE "grpc.authority_override" + +namespace grpc_core { + +/// Returns a channel argument containing \a authority. +grpc_arg CreateAuthorityOverrideChannelArg(const char* authority) { + return grpc_channel_arg_string_create( + const_cast(GRPC_ARG_AUTHORITY_OVERRIDE), + const_cast(authority)); +} + +/// Returns the authority override from \a args or nullptr. +const char* FindAuthorityOverrideInArgs(const grpc_channel_args* args) { + return grpc_channel_args_find_string(args, GRPC_ARG_AUTHORITY_OVERRIDE); +} + +} // namespace grpc_core diff --git a/src/core/lib/transport/authority_override.h b/src/core/lib/transport/authority_override.h new file mode 100644 index 00000000000..9e584b56cb7 --- /dev/null +++ b/src/core/lib/transport/authority_override.h @@ -0,0 +1,32 @@ +// +// Copyright 2020 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 GRPC_CORE_LIB_TRANSPORT_AUTHORITY_OVERRIDE_H +#define GRPC_CORE_LIB_TRANSPORT_AUTHORITY_OVERRIDE_H + +#include + +namespace grpc_core { + +/// Returns a channel argument containing \a authority. +grpc_arg CreateAuthorityOverrideChannelArg(const char* authority); + +/// Returns the authority override from \a args or nullptr. +const char* FindAuthorityOverrideInArgs(const grpc_channel_args* args); + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_TRANSPORT_AUTHORITY_OVERRIDE_H */ diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 5b9dc43d30d..f0e8d2058be 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -403,7 +403,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/security/transport/secure_endpoint.cc', 'src/core/lib/security/transport/security_handshaker.cc', 'src/core/lib/security/transport/server_auth_filter.cc', - 'src/core/lib/security/transport/target_authority_table.cc', 'src/core/lib/security/transport/tsi_error.cc', 'src/core/lib/security/util/json_util.cc', 'src/core/lib/slice/b64.cc', @@ -432,6 +431,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/server.cc', 'src/core/lib/surface/validate_metadata.cc', 'src/core/lib/surface/version.cc', + 'src/core/lib/transport/authority_override.cc', 'src/core/lib/transport/bdp_estimator.cc', 'src/core/lib/transport/byte_stream.cc', 'src/core/lib/transport/connectivity_state.cc', diff --git a/test/core/slice/BUILD b/test/core/slice/BUILD index 8018505e3be..9be57ab7b5e 100644 --- a/test/core/slice/BUILD +++ b/test/core/slice/BUILD @@ -116,36 +116,6 @@ grpc_cc_test( ], ) -grpc_cc_test( - name = "slice_hash_table_test", - srcs = ["slice_hash_table_test.cc"], - external_deps = [ - "gtest", - ], - language = "C++", - uses_polling = False, - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "slice_weak_hash_table_test", - srcs = ["slice_weak_hash_table_test.cc"], - external_deps = [ - "gtest", - ], - language = "C++", - uses_polling = False, - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:grpc_test_util", - ], -) - grpc_cc_test( name = "b64_test", srcs = ["b64_test.cc"], diff --git a/test/core/slice/slice_hash_table_test.cc b/test/core/slice/slice_hash_table_test.cc deleted file mode 100644 index ceab284cb43..00000000000 --- a/test/core/slice/slice_hash_table_test.cc +++ /dev/null @@ -1,227 +0,0 @@ -/* - * - * Copyright 2017 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 "src/core/lib/slice/slice_hash_table.h" - -#include - -#include - -#include - -#include -#include -#include - -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" -#include "test/core/util/test_config.h" - -namespace grpc_core { -namespace { - -typedef SliceHashTable> TestHashTable; - -struct TestEntry { - const char* key; - const char* value; -}; - -void CheckValues(const std::vector& input, - const TestHashTable& table) { - for (const TestEntry& expected : input) { - grpc_slice key = grpc_slice_from_static_string(expected.key); - const grpc_core::UniquePtr* actual = table.Get(key); - ASSERT_NE(actual, nullptr); - EXPECT_STREQ(expected.value, actual->get()); - grpc_slice_unref(key); - } -} - -void CheckNonExistentValue(const char* key_string, const TestHashTable& table) { - grpc_slice key = grpc_slice_from_static_string(key_string); - ASSERT_EQ(nullptr, table.Get(key)); - grpc_slice_unref(key); -} - -void PopulateEntries(const std::vector& input, - TestHashTable::Entry* output) { - for (size_t i = 0; i < input.size(); ++i) { - output[i].key = grpc_slice_from_copied_string(input[i].key); - output[i].value = grpc_core::UniquePtr(gpr_strdup(input[i].value)); - } -} - -RefCountedPtr CreateTableFromEntries( - const std::vector& test_entries, - TestHashTable::ValueCmp value_cmp) { - TestHashTable::Entry* entries = static_cast( - gpr_zalloc(sizeof(*entries) * test_entries.size())); - PopulateEntries(test_entries, entries); - RefCountedPtr table = - TestHashTable::Create(test_entries.size(), entries, value_cmp); - gpr_free(entries); - return table; -} - -TEST(SliceHashTable, Basic) { - const std::vector test_entries = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}, - {"key_3", "value_3"}, {"key_4", "value_4"}, {"key_5", "value_5"}, - {"key_6", "value_6"}, {"key_7", "value_7"}, {"key_8", "value_8"}, - {"key_9", "value_9"}, {"key_10", "value_10"}, {"key_11", "value_11"}, - {"key_12", "value_12"}, {"key_13", "value_13"}, {"key_14", "value_14"}, - {"key_15", "value_15"}, {"key_16", "value_16"}, {"key_17", "value_17"}, - {"key_18", "value_18"}, {"key_19", "value_19"}, {"key_20", "value_20"}, - {"key_21", "value_21"}, {"key_22", "value_22"}, {"key_23", "value_23"}, - {"key_24", "value_24"}, {"key_25", "value_25"}, {"key_26", "value_26"}, - {"key_27", "value_27"}, {"key_28", "value_28"}, {"key_29", "value_29"}, - {"key_30", "value_30"}, {"key_31", "value_31"}, {"key_32", "value_32"}, - {"key_33", "value_33"}, {"key_34", "value_34"}, {"key_35", "value_35"}, - {"key_36", "value_36"}, {"key_37", "value_37"}, {"key_38", "value_38"}, - {"key_39", "value_39"}, {"key_40", "value_40"}, {"key_41", "value_41"}, - {"key_42", "value_42"}, {"key_43", "value_43"}, {"key_44", "value_44"}, - {"key_45", "value_45"}, {"key_46", "value_46"}, {"key_47", "value_47"}, - {"key_48", "value_48"}, {"key_49", "value_49"}, {"key_50", "value_50"}, - {"key_51", "value_51"}, {"key_52", "value_52"}, {"key_53", "value_53"}, - {"key_54", "value_54"}, {"key_55", "value_55"}, {"key_56", "value_56"}, - {"key_57", "value_57"}, {"key_58", "value_58"}, {"key_59", "value_59"}, - {"key_60", "value_60"}, {"key_61", "value_61"}, {"key_62", "value_62"}, - {"key_63", "value_63"}, {"key_64", "value_64"}, {"key_65", "value_65"}, - {"key_66", "value_66"}, {"key_67", "value_67"}, {"key_68", "value_68"}, - {"key_69", "value_69"}, {"key_70", "value_70"}, {"key_71", "value_71"}, - {"key_72", "value_72"}, {"key_73", "value_73"}, {"key_74", "value_74"}, - {"key_75", "value_75"}, {"key_76", "value_76"}, {"key_77", "value_77"}, - {"key_78", "value_78"}, {"key_79", "value_79"}, {"key_80", "value_80"}, - {"key_81", "value_81"}, {"key_82", "value_82"}, {"key_83", "value_83"}, - {"key_84", "value_84"}, {"key_85", "value_85"}, {"key_86", "value_86"}, - {"key_87", "value_87"}, {"key_88", "value_88"}, {"key_89", "value_89"}, - {"key_90", "value_90"}, {"key_91", "value_91"}, {"key_92", "value_92"}, - {"key_93", "value_93"}, {"key_94", "value_94"}, {"key_95", "value_95"}, - {"key_96", "value_96"}, {"key_97", "value_97"}, {"key_98", "value_98"}, - {"key_99", "value_99"}, - }; - RefCountedPtr table = - CreateTableFromEntries(test_entries, nullptr); - // Check contents of table. - CheckValues(test_entries, *table); - CheckNonExistentValue("XX", *table); -} - -int StringCmp(const grpc_core::UniquePtr& a, - const grpc_core::UniquePtr& b) { - return strcmp(a.get(), b.get()); -} - -int PointerCmp(const grpc_core::UniquePtr& a, - const grpc_core::UniquePtr& b) { - return GPR_ICMP(a.get(), b.get()); -} - -TEST(SliceHashTable, CmpEqual) { - const std::vector test_entries_a = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, StringCmp); - // table_a equals itself. - EXPECT_EQ(0, TestHashTable::Cmp(*table_a, *table_a)); - // table_a equals table_b. - EXPECT_EQ(0, TestHashTable::Cmp(*table_a, *table_b)); -} - -TEST(SliceHashTable, CmpDifferentSizes) { - // table_a has 3 entries, table_b has only 2. - const std::vector test_entries_a = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = {{"key_0", "value_0"}, - {"key_1", "value_1"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, StringCmp); - EXPECT_GT(TestHashTable::Cmp(*table_a, *table_b), 0); - EXPECT_LT(TestHashTable::Cmp(*table_b, *table_a), 0); -} - -TEST(SliceHashTable, CmpDifferentKey) { - // One key doesn't match and is lexicographically "smaller". - const std::vector test_entries_a = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = { - {"key_zz", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, StringCmp); - EXPECT_GT(TestHashTable::Cmp(*table_a, *table_b), 0); - EXPECT_LT(TestHashTable::Cmp(*table_b, *table_a), 0); -} - -TEST(SliceHashTable, CmpDifferentValue) { - // One value doesn't match. - const std::vector test_entries_a = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = { - {"key_0", "value_z"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, StringCmp); - EXPECT_LT(TestHashTable::Cmp(*table_a, *table_b), 0); - EXPECT_GT(TestHashTable::Cmp(*table_b, *table_a), 0); -} - -TEST(SliceHashTable, CmpDifferentCmpFunctions) { - // Same values but different "equals" functions. - const std::vector test_entries_a = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = { - {"key_0", "value_0"}, {"key_1", "value_1"}, {"key_2", "value_2"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, PointerCmp); - EXPECT_NE(TestHashTable::Cmp(*table_a, *table_b), 0); -} - -TEST(SliceHashTable, CmpEmptyKeysDifferentValue) { - // Same (empty) key, different values. - const std::vector test_entries_a = {{"", "value_0"}}; - RefCountedPtr table_a = - CreateTableFromEntries(test_entries_a, StringCmp); - const std::vector test_entries_b = {{"", "value_1"}}; - RefCountedPtr table_b = - CreateTableFromEntries(test_entries_b, PointerCmp); - EXPECT_NE(TestHashTable::Cmp(*table_a, *table_b), 0); -} - -} // namespace -} // namespace grpc_core - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - grpc::testing::TestEnvironment env(argc, argv); - grpc_core::ExecCtx::GlobalInit(); - int result = RUN_ALL_TESTS(); - grpc_core::ExecCtx::GlobalShutdown(); - return result; -} diff --git a/test/core/slice/slice_weak_hash_table_test.cc b/test/core/slice/slice_weak_hash_table_test.cc deleted file mode 100644 index 09e1f4e3de8..00000000000 --- a/test/core/slice/slice_weak_hash_table_test.cc +++ /dev/null @@ -1,107 +0,0 @@ -/* - * - * Copyright 2017 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 "src/core/lib/slice/slice_weak_hash_table.h" - -#include -#include - -#include - -#include -#include -#include - -#include "src/core/lib/gpr/useful.h" -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" -#include "test/core/util/test_config.h" - -namespace grpc_core { -namespace { - -grpc_slice BuildRefCountedKey(const char* key_str) { - const size_t key_length = strlen(key_str); - grpc_slice key = grpc_slice_malloc_large(key_length); - memcpy(GRPC_SLICE_START_PTR(key), key_str, key_length); - return key; -} - -TEST(SliceWeakHashTable, Basic) { - auto table = SliceWeakHashTable, 10>::Create(); - // Single key-value insertion. - grpc_slice key = BuildRefCountedKey("key"); - grpc_slice_ref(key); // Get doesn't own. - table->Add(key, grpc_core::UniquePtr(gpr_strdup("value"))); - ASSERT_NE(table->Get(key), nullptr); - ASSERT_STREQ(table->Get(key)->get(), "value"); - grpc_slice_unref(key); - // Unknown key. - ASSERT_EQ(table->Get(grpc_slice_from_static_string("unknown_key")), nullptr); -} - -TEST(SliceWeakHashTable, ValueTypeConstructor) { - struct Value { - Value() : a(123) {} - int a; - }; - auto table = SliceWeakHashTable::Create(); - grpc_slice key = BuildRefCountedKey("key"); - grpc_slice_ref(key); // Get doesn't own. - table->Add(key, Value()); - ASSERT_EQ(table->Get(key)->a, 123); - grpc_slice_unref(key); -} - -TEST(SliceWeakHashTable, ForceOverload) { - constexpr int kTableSize = 10; - auto table = - SliceWeakHashTable, kTableSize>::Create(); - // Insert a multiple of the maximum size table. - for (int i = 0; i < kTableSize * 2; ++i) { - std::ostringstream oss; - oss << "key-" << i; - grpc_slice key = BuildRefCountedKey(oss.str().c_str()); - oss.clear(); - oss << "value-" << i; - table->Add(key, grpc_core::UniquePtr(gpr_strdup(oss.str().c_str()))); - } - // Verify that some will have been replaced. - int num_missing = 0; - for (int i = 0; i < kTableSize * 2; ++i) { - std::ostringstream oss; - oss << "key-" << i; - grpc_slice key = BuildRefCountedKey(oss.str().c_str()); - if (table->Get(key) == nullptr) num_missing++; - grpc_slice_unref(key); - } - // At least kTableSize elements will be missing. - ASSERT_GE(num_missing, kTableSize); -} - -} // namespace -} // namespace grpc_core - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - grpc::testing::TestEnvironment env(argc, argv); - grpc_core::ExecCtx::GlobalInit(); - int result = RUN_ALL_TESTS(); - grpc_core::ExecCtx::GlobalShutdown(); - return result; -} diff --git a/test/cpp/client/client_channel_stress_test.cc b/test/cpp/client/client_channel_stress_test.cc index f2ef30ef9ff..f9b7bc4343f 100644 --- a/test/cpp/client/client_channel_stress_test.cc +++ b/test/cpp/client/client_channel_stress_test.cc @@ -44,6 +44,7 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/gprpp/thd.h" #include "src/core/lib/iomgr/sockaddr.h" +#include "src/core/lib/transport/authority_override.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -228,8 +229,8 @@ class ClientChannelStressTest { GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; GPR_ASSERT(grpc_parse_uri(lb_uri, &address)); - grpc_arg arg = - grpc_core::CreateGrpclbBalancerNameArg(addr.balancer_name.c_str()); + grpc_arg arg = grpc_core::CreateAuthorityOverrideChannelArg( + addr.balancer_name.c_str()); grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); addresses.emplace_back(address.addr, address.len, args); diff --git a/test/cpp/end2end/grpclb_end2end_test.cc b/test/cpp/end2end/grpclb_end2end_test.cc index 97ea12df7ea..45150fb54ba 100644 --- a/test/cpp/end2end/grpclb_end2end_test.cc +++ b/test/cpp/end2end/grpclb_end2end_test.cc @@ -48,6 +48,7 @@ #include "src/core/lib/gprpp/ref_counted_ptr.h" #include "src/core/lib/iomgr/sockaddr.h" #include "src/core/lib/security/credentials/fake/fake_credentials.h" +#include "src/core/lib/transport/authority_override.h" #include "src/cpp/client/secure_credentials.h" #include "src/cpp/server/secure_server_credentials.h" @@ -554,8 +555,8 @@ class GrpclbEnd2endTest : public ::testing::Test { GPR_ASSERT(lb_uri != nullptr); grpc_resolved_address address; GPR_ASSERT(grpc_parse_uri(lb_uri, &address)); - grpc_arg arg = - grpc_core::CreateGrpclbBalancerNameArg(addr.balancer_name.c_str()); + grpc_arg arg = grpc_core::CreateAuthorityOverrideChannelArg( + addr.balancer_name.c_str()); grpc_channel_args* args = grpc_channel_args_copy_and_add(nullptr, &arg, 1); addresses.emplace_back(address.addr, address.len, args); diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 42ad53a6b6a..beaf200da17 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -1778,8 +1778,6 @@ src/core/lib/security/transport/secure_endpoint.h \ src/core/lib/security/transport/security_handshaker.cc \ src/core/lib/security/transport/security_handshaker.h \ src/core/lib/security/transport/server_auth_filter.cc \ -src/core/lib/security/transport/target_authority_table.cc \ -src/core/lib/security/transport/target_authority_table.h \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/transport/tsi_error.h \ src/core/lib/security/util/json_util.cc \ @@ -1790,13 +1788,11 @@ src/core/lib/slice/percent_encoding.cc \ src/core/lib/slice/percent_encoding.h \ src/core/lib/slice/slice.cc \ src/core/lib/slice/slice_buffer.cc \ -src/core/lib/slice/slice_hash_table.h \ src/core/lib/slice/slice_intern.cc \ src/core/lib/slice/slice_internal.h \ src/core/lib/slice/slice_string_helpers.cc \ src/core/lib/slice/slice_string_helpers.h \ src/core/lib/slice/slice_utils.h \ -src/core/lib/slice/slice_weak_hash_table.h \ src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.h \ src/core/lib/surface/byte_buffer.cc \ @@ -1830,6 +1826,8 @@ src/core/lib/surface/server.h \ src/core/lib/surface/validate_metadata.cc \ src/core/lib/surface/validate_metadata.h \ src/core/lib/surface/version.cc \ +src/core/lib/transport/authority_override.cc \ +src/core/lib/transport/authority_override.h \ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/byte_stream.cc \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index d33ceb61599..df7f5af5697 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1597,8 +1597,6 @@ src/core/lib/security/transport/secure_endpoint.h \ src/core/lib/security/transport/security_handshaker.cc \ src/core/lib/security/transport/security_handshaker.h \ src/core/lib/security/transport/server_auth_filter.cc \ -src/core/lib/security/transport/target_authority_table.cc \ -src/core/lib/security/transport/target_authority_table.h \ src/core/lib/security/transport/tsi_error.cc \ src/core/lib/security/transport/tsi_error.h \ src/core/lib/security/util/json_util.cc \ @@ -1609,13 +1607,11 @@ src/core/lib/slice/percent_encoding.cc \ src/core/lib/slice/percent_encoding.h \ src/core/lib/slice/slice.cc \ src/core/lib/slice/slice_buffer.cc \ -src/core/lib/slice/slice_hash_table.h \ src/core/lib/slice/slice_intern.cc \ src/core/lib/slice/slice_internal.h \ src/core/lib/slice/slice_string_helpers.cc \ src/core/lib/slice/slice_string_helpers.h \ src/core/lib/slice/slice_utils.h \ -src/core/lib/slice/slice_weak_hash_table.h \ src/core/lib/surface/README.md \ src/core/lib/surface/api_trace.cc \ src/core/lib/surface/api_trace.h \ @@ -1651,6 +1647,8 @@ src/core/lib/surface/validate_metadata.cc \ src/core/lib/surface/validate_metadata.h \ src/core/lib/surface/version.cc \ src/core/lib/transport/README.md \ +src/core/lib/transport/authority_override.cc \ +src/core/lib/transport/authority_override.h \ src/core/lib/transport/bdp_estimator.cc \ src/core/lib/transport/bdp_estimator.h \ src/core/lib/transport/byte_stream.cc \ diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 6227235d23b..fa88b63969d 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -5453,54 +5453,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "slice_hash_table_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "slice_weak_hash_table_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": false - }, { "args": [], "benchmark": false,