1 // Copyright 2023 gRPC authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // 16 // Automatically generated by tools/codegen/core/gen_config_vars.py 17 // 18 19 #ifndef GRPC_SRC_CORE_CONFIG_CONFIG_VARS_H 20 #define GRPC_SRC_CORE_CONFIG_CONFIG_VARS_H 21 22 #include <grpc/support/port_platform.h> 23 #include <stdint.h> 24 25 #include <atomic> 26 #include <string> 27 28 #include "absl/strings/string_view.h" 29 #include "absl/types/optional.h" 30 31 namespace grpc_core { 32 33 class GPR_DLL ConfigVars { 34 public: 35 struct Overrides { 36 absl::optional<int32_t> client_channel_backup_poll_interval_ms; 37 absl::optional<bool> enable_fork_support; 38 absl::optional<bool> abort_on_leaks; 39 absl::optional<bool> not_use_system_ssl_roots; 40 absl::optional<bool> cpp_experimental_disable_reflection; 41 absl::optional<std::string> dns_resolver; 42 absl::optional<std::string> verbosity; 43 absl::optional<std::string> poll_strategy; 44 absl::optional<std::string> system_ssl_roots_dir; 45 absl::optional<std::string> default_ssl_roots_file_path; 46 absl::optional<std::string> ssl_cipher_suites; 47 absl::optional<std::string> experiments; 48 absl::optional<std::string> trace; 49 }; 50 ConfigVars(const ConfigVars&) = delete; 51 ConfigVars& operator=(const ConfigVars&) = delete; 52 // Get the core configuration; if it does not exist, create it. Get()53 static const ConfigVars& Get() { 54 auto* p = config_vars_.load(std::memory_order_acquire); 55 if (p != nullptr) return *p; 56 return Load(); 57 } 58 static void SetOverrides(const Overrides& overrides); 59 // Drop the config vars. Users must ensure no other threads are 60 // accessing the configuration. 61 static void Reset(); 62 std::string ToString() const; 63 // A comma separated list of currently active experiments. Experiments may be 64 // prefixed with a '-' to disable them. Experiments()65 absl::string_view Experiments() const { return experiments_; } 66 // Declares the interval in ms between two backup polls on client channels. 67 // These polls are run in the timer thread so that gRPC can process connection 68 // failures while there is no active polling thread. They help reconnect 69 // disconnected client channels (mostly due to idleness), so that the next RPC 70 // on this channel won't fail. Set to 0 to turn off the backup polls. ClientChannelBackupPollIntervalMs()71 int32_t ClientChannelBackupPollIntervalMs() const { 72 return client_channel_backup_poll_interval_ms_; 73 } 74 // Declares which DNS resolver to use. The default is ares if gRPC is built 75 // with c-ares support. Otherwise, the value of this environment variable is 76 // ignored. DnsResolver()77 absl::string_view DnsResolver() const { return dns_resolver_; } 78 // A comma separated list of tracers that provide additional insight into how 79 // gRPC C core is processing requests via debug logs. Trace()80 absl::string_view Trace() const { return trace_; } 81 // Logging verbosity. Verbosity()82 absl::string_view Verbosity() const { return verbosity_; } 83 // Enable fork support EnableForkSupport()84 bool EnableForkSupport() const { return enable_fork_support_; } 85 // Declares which polling engines to try when starting gRPC. This is a 86 // comma-separated list of engines, which are tried in priority order first -> 87 // last. PollStrategy()88 absl::string_view PollStrategy() const { return poll_strategy_; } 89 // A debugging aid to cause a call to abort() when gRPC objects are leaked 90 // past grpc_shutdown() AbortOnLeaks()91 bool AbortOnLeaks() const { return abort_on_leaks_; } 92 // Custom directory to SSL Roots 93 std::string SystemSslRootsDir() const; 94 // Path to the default SSL roots file. 95 std::string DefaultSslRootsFilePath() const; 96 // Disable loading system root certificates. NotUseSystemSslRoots()97 bool NotUseSystemSslRoots() const { return not_use_system_ssl_roots_; } 98 // A colon separated list of cipher suites to use with OpenSSL SslCipherSuites()99 absl::string_view SslCipherSuites() const { return ssl_cipher_suites_; } 100 // EXPERIMENTAL. Only respected when there is a dependency on 101 // :grpc++_reflection. If true, no reflection server will be automatically 102 // added. CppExperimentalDisableReflection()103 bool CppExperimentalDisableReflection() const { 104 return cpp_experimental_disable_reflection_; 105 } 106 107 private: 108 explicit ConfigVars(const Overrides& overrides); 109 static const ConfigVars& Load(); 110 static std::atomic<ConfigVars*> config_vars_; 111 int32_t client_channel_backup_poll_interval_ms_; 112 bool enable_fork_support_; 113 bool abort_on_leaks_; 114 bool not_use_system_ssl_roots_; 115 bool cpp_experimental_disable_reflection_; 116 std::string dns_resolver_; 117 std::string verbosity_; 118 std::string poll_strategy_; 119 std::string ssl_cipher_suites_; 120 std::string experiments_; 121 std::string trace_; 122 absl::optional<std::string> override_system_ssl_roots_dir_; 123 absl::optional<std::string> override_default_ssl_roots_file_path_; 124 }; 125 126 } // namespace grpc_core 127 128 #endif // GRPC_SRC_CORE_CONFIG_CONFIG_VARS_H 129