1 // 2 // Copyright 2022 gRPC authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef GRPC_SRC_CORE_EXT_XDS_XDS_CLIENT_GRPC_H 18 #define GRPC_SRC_CORE_EXT_XDS_XDS_CLIENT_GRPC_H 19 20 #include <grpc/support/port_platform.h> 21 22 #include <memory> 23 24 #include "absl/status/statusor.h" 25 #include "absl/strings/string_view.h" 26 27 #include <grpc/grpc.h> 28 29 #include "src/core/ext/xds/certificate_provider_store.h" 30 #include "src/core/ext/xds/xds_bootstrap_grpc.h" 31 #include "src/core/ext/xds/xds_client.h" 32 #include "src/core/lib/channel/channel_args.h" 33 #include "src/core/lib/gpr/useful.h" 34 #include "src/core/lib/gprpp/orphanable.h" 35 #include "src/core/lib/gprpp/ref_counted_ptr.h" 36 #include "src/core/lib/iomgr/iomgr_fwd.h" 37 38 namespace grpc_core { 39 40 class GrpcXdsClient : public XdsClient { 41 public: 42 // Factory function to get or create the global XdsClient instance. 43 static absl::StatusOr<RefCountedPtr<GrpcXdsClient>> GetOrCreate( 44 const ChannelArgs& args, const char* reason); 45 46 // Do not instantiate directly -- use GetOrCreate() instead. 47 GrpcXdsClient(std::unique_ptr<GrpcXdsBootstrap> bootstrap, 48 const ChannelArgs& args); 49 ~GrpcXdsClient() override; 50 51 // Helpers for encoding the XdsClient object in channel args. ChannelArgName()52 static absl::string_view ChannelArgName() { 53 return "grpc.internal.xds_client"; 54 } ChannelArgsCompare(const XdsClient * a,const XdsClient * b)55 static int ChannelArgsCompare(const XdsClient* a, const XdsClient* b) { 56 return QsortCompare(a, b); 57 } 58 59 grpc_pollset_set* interested_parties() const; 60 certificate_provider_store()61 CertificateProviderStore& certificate_provider_store() const { 62 return *certificate_provider_store_; 63 } 64 65 private: 66 OrphanablePtr<CertificateProviderStore> certificate_provider_store_; 67 }; 68 69 namespace internal { 70 void SetXdsChannelArgsForTest(grpc_channel_args* args); 71 void UnsetGlobalXdsClientForTest(); 72 // Sets bootstrap config to be used when no env var is set. 73 // Does not take ownership of config. 74 void SetXdsFallbackBootstrapConfig(const char* config); 75 } // namespace internal 76 77 } // namespace grpc_core 78 79 #endif // GRPC_SRC_CORE_EXT_XDS_XDS_CLIENT_GRPC_H 80