Skip to main content

Module config

Module config 

Source
Expand description

Global bhtune configuration, including the shared [tuning] timing policy and the CLI flag > env var > TOML config file > built-in default precedence used by settings that expose command-line or environment overrides.

Structs§

BhtuneConfig
bhtune’s configuration, loaded from an optional TOML file. Every field is optional; a value missing from the file (or the file itself missing) falls back to the env var / CLI flag / built-in default resolution in the resolve_* functions below.
ConfigPathResolution
Path-resolution result for the TOML config store: either an explicit --config path or the auto-discovered default, plus whether a missing file is acceptable at that tier.
ConfigPolicyUpdate
Config-page-owned settings that can be patched in place while preserving every unrelated key and comment in the source TOML.
ConfigSaveResult
Result of safely saving a patched TOML config file.
DemoPolicy
Limits applied to the public simulator-only demo surface.
DemoPolicyConfig
Optional declarations of the fixed DemoPolicy contract.
EffectiveTuningConfig
Concrete tuning timing policy after absent TOML keys have received built-in defaults.
LoadedConfigStore
A path-aware TOML config snapshot suitable for server-side read/modify/write flows.
LogConfig
Logging configuration keys (a [log] table in bhtune.toml), consumed by crate::logging::resolve_log_settings. Every field is optional and falls back through the same CLI flag > env var > config file > default precedence as the rest of BhtuneConfig.
TuningConfig
Optional values authored in the [tuning] table.
TuningConfigSources
Per-field provenance for the effective [tuning] policy.

Enums§

ConfigStoreError
Typed errors for the path-aware TOML config store used by the server config page.
ServerMode
Runtime server exposure mode. Full mode preserves the normal live-plant API; Demo mode is an explicitly restricted, simulator-only surface intended for public demonstrations.
TuningConfigError
Validation error for concrete tuning timing values.
TuningConfigSource
Origin of one effective tuning value.

Constants§

DEFAULT_BIND_ADDR
Default address bhtune-server binds to when nothing else specifies one – loopback only, matching the “v1 binds to 127.0.0.1 by default” decision in AGENTS.md. Lives alongside DEFAULT_BRIDGE_HOST in this shared config module (rather than in bhtune-server itself) even though only the server binary ever calls resolve_bind_addr, the same way templates/log below are settings only some commands consume – one bhtune.toml file and one precedence chain for every bhtune setting, CLI or server.
DEFAULT_BRIDGE_HOST
Default opcda-bridge gateway address bhtune connects to when nothing else specifies one.
DEFAULT_TUNING_MRFT_DELAY_SECS
Built-in pre/post-MRFT recording padding when [tuning].mrft_delay_secs is absent.
DEFAULT_TUNING_OP_TIMEOUT_SECS
Built-in per-driver-operation timeout when [tuning].op_timeout_secs is absent.
DEFAULT_TUNING_POLL_INTERVAL_MS
Built-in driver polling interval when [tuning].poll_interval_ms is absent.
DEFAULT_TUNING_RESTORE_TIMEOUT_SECS
Built-in post-run restoration timeout when [tuning].restore_timeout_secs is absent.
DEFAULT_TUNING_TIMEOUT_SECS
Built-in whole-run timeout when [tuning].timeout_secs is absent.
DEMO_ACCEPTED_STARTS_PER_CLIENT_IP
Accepted Demo tune starts allowed for one client IP in a quota window.
DEMO_ACCEPTED_STARTS_PER_TOKEN
Accepted Demo tune starts allowed for one session token in a quota window.
DEMO_ACCEPTED_START_WINDOW_SECS
Fixed window used by the accepted-start quotas.
DEMO_CLEANUP_INTERVAL_SECS
Interval between expired-session and excess-history cleanup passes.
DEMO_COOKIE_NAME
Name of the host-only anonymous Demo session cookie.
DEMO_CYCLES_COUNT_DEFAULT
Default relay-cycle count used by the Demo form.
DEMO_CYCLES_COUNT_MAX
Maximum relay-cycle count accepted by the public Demo.
DEMO_CYCLES_COUNT_MIN
Minimum relay-cycle count accepted by the public Demo.
DEMO_CYCLES_SKIP_DEFAULT
Default relay-cycle skip count used by the Demo form.
DEMO_CYCLES_SKIP_MAX
Maximum relay-cycle skip count accepted by the public Demo.
DEMO_CYCLES_SKIP_MIN
Minimum relay-cycle skip count accepted by the public Demo.
DEMO_MAX_ACTIVE_RUNS_GLOBAL
Maximum number of Demo tunes that may be active across all visitors.
DEMO_MAX_ACTIVE_RUNS_PER_VISITOR
Maximum number of Demo tunes that may be active for one visitor.
DEMO_MAX_JSON_BODY_BYTES
Maximum JSON request-body size accepted by the Demo API.
DEMO_MAX_RUNS_PER_SESSION
Maximum accepted demo runs retained per session, independent of active-run concurrency.
DEMO_MAX_SSE_GLOBAL
Maximum number of simultaneous Demo SSE streams across all visitors.
DEMO_MAX_SSE_PER_VISITOR
Maximum number of simultaneous SSE streams for one visitor.
DEMO_MAX_TUNE_RUN_ROWS_GLOBAL
Maximum number of current Demo-owned tune_runs rows in the database.
DEMO_NOISE_PROTECTION_SECS_DEFAULT
Default switch noise-protection delay used by the Demo form.
DEMO_NOISE_PROTECTION_SECS_MAX
Maximum switch noise-protection delay accepted by the public Demo.
DEMO_NOISE_PROTECTION_SECS_MIN
Minimum switch noise-protection delay accepted by the public Demo.
DEMO_ORDINARY_REQUEST_CONCURRENCY
Maximum number of ordinary Demo API requests processed concurrently.
DEMO_ORDINARY_REQUEST_TIMEOUT_SECS
Timeout applied to an ordinary, non-streaming Demo API request.
DEMO_POLL_INTERVAL_MS
Fixed simulator polling interval used by public Demo tunes.
DEMO_RANGE_ENDPOINT_MAX
Maximum PV/MV range endpoint accepted by the public Demo.
DEMO_RANGE_ENDPOINT_MIN
Minimum PV/MV range endpoint accepted by the public Demo.
DEMO_RANGE_HIGH
Default PV and MV upper bound used by public Demo runs.
DEMO_RANGE_LOW
Default PV and MV lower bound used by public Demo runs.
DEMO_RANGE_SPAN_MAX
Maximum PV/MV span accepted by the public Demo.
DEMO_RANGE_SPAN_MIN
Minimum PV/MV span accepted by the public Demo.
DEMO_RELAY_AMP_DEFAULT
Default relay amplitude used by the Demo form.
DEMO_RELAY_AMP_MAX
Maximum relay amplitude accepted by the public Demo.
DEMO_RELAY_AMP_MIN
Minimum relay amplitude accepted by the public Demo.
DEMO_RETAINED_RUNS_PER_VISITOR
Maximum number of completed Demo runs retained for one visitor.
DEMO_RUN_TIMEOUT_SECS
Fixed whole-run timeout used by public Demo tunes.
DEMO_SESSION_TTL_SECS
Fixed lifetime of an anonymous public Demo visitor session.
DEMO_SIM_DEAD_TIME_DEFAULT
Default simulator dead time used by the Demo form.
DEMO_SIM_DEAD_TIME_MAX
Maximum simulator dead time accepted by the public Demo.
DEMO_SIM_DEAD_TIME_MIN
Minimum simulator dead time accepted by the public Demo.
DEMO_SIM_GAIN_ABS_MIN
Minimum non-zero process-gain magnitude accepted by the public Demo.
DEMO_SIM_GAIN_DEFAULT
Default simulator process gain used by the Demo form.
DEMO_SIM_GAIN_MAX
Maximum process-gain magnitude accepted by the public Demo.
DEMO_SIM_INITIAL_VALUE_DEFAULT
Default simulator PV and MV starting value used by the Demo form.
DEMO_SIM_NOISE_DEFAULT
Default simulator noise amplitude used by the Demo form.
DEMO_SIM_NOISE_MAX_PV_SPAN_FRACTION
Maximum simulator noise amplitude as a fraction of the configured PV span.
DEMO_SIM_NOISE_MIN
Minimum simulator noise amplitude accepted by the public Demo.
DEMO_SIM_SEED_DEFAULT
Default simulator random seed used by the Demo form.
DEMO_SIM_SEED_MAX
Largest simulator seed accepted by the public Demo.
DEMO_SIM_TAU_DEFAULT
Default simulator time constant used by the Demo form.
DEMO_SIM_TAU_MAX
Maximum simulator time constant accepted by the public Demo.
DEMO_SIM_TAU_MIN
Minimum simulator time constant accepted by the public Demo.
DEMO_SSE_LIFETIME_SECS
Absolute lifetime of one Demo SSE stream.
DEMO_TAG_NAME
Fixed persisted/display label used by public Demo runs.
DEMO_TEMPLATE_NAME
Built-in template exposed by the public Demo.
MAX_TUNING_MRFT_DELAY_SECS
Largest supported pre/post-MRFT recording delay.
MIN_OPC_RESTORE_TIMEOUT_SECS
Minimum restoration timeout for OPC DA runs.

Functions§

config_path_from
Derive bhtune’s config file location from raw environment values rather than reading std::env directly – keeps discovery fully unit-testable across every permutation without mutating real process environment variables.
default_allow_uncertain_quality
The default configuration-page quality policy: absent allow_uncertain_quality resolves to true rather than bool’s usual false.
default_db_path_from
Derive bhtune’s default database location the same way config files are discovered, but under the platform’s data directory rather than its config directory – a database is persistent user data, not settings, per the XDG base directory specification.
default_log_dir_from
Derive bhtune’s default log directory the same way the database path is derived (see default_db_path_from) – under the platform data directory, not next to the compiled binary. Unlike opcda-bridge-gateway’s equivalent (log_dir_from_exe), a cargo installed binary’s own directory (e.g. ~/.cargo/bin/) isn’t a sensible place to write logs, and bhtune already has this exact precedence machinery for the database, so the log directory reuses it rather than inventing a second convention.
load_config
Resolve and load the bhtune config: an explicit --config path if given, otherwise the platform’s auto-discovered path (silently falls back to defaults if none of the relevant environment variables are set, or if the discovered file doesn’t exist).
load_config_file
Load a bhtune config from path.
load_config_store
Load the path-aware TOML config store using real environment-based auto-discovery.
load_config_store_from
Load the path-aware TOML config store using injected path-discovery inputs so every resolution branch stays unit-testable without mutating process-global environment variables.
load_user_templates
Resolve and load the user-supplied DCS/PLC template catalog (template-user-catalog): --templates / BHTUNE_TEMPLATES (already folded into cli_templates by clap’s env attribute) / the config file’s templates key, or else the platform’s auto-discovered templates.toml next to bhtune.toml (see templates_path_from) – CLI flag > env var > config file > platform default, the same precedence chain as every other bhtune setting.
parse_config_contents
Parses the in-memory TOML representation of a config file.
patch_allow_uncertain_quality
Patch only allow_uncertain_quality while preserving every unrelated key, comment, and formatting detail the source document already had.
patch_retention_days
Patch only retention_days while preserving every unrelated key, comment, and formatting detail the source document already had. None removes the key entirely.
patch_tuning_config
Patch all five [tuning] values while preserving unrelated keys, comments, and formatting. A None value removes only that key.
resolve_and_validate_tuning_config
Resolve and validate a raw [tuning] table in one step.
resolve_bind_addr
Resolve bhtune-server’s bind address with CLI flag > env var > config file > default precedence, matching resolve_bridge_host’s shape exactly. bhtune-server has no clap dependency (see AGENTS.md’s “Deferred setup”), so unlike resolve_bridge_host the env var isn’t folded in by a derive attribute upstream – callers pass std::env::var("BHTUNE_BIND").ok() (or a real CLI flag, if one is ever added) directly as cli_bind.
resolve_bridge_host
Resolve the opcda-bridge gateway address with CLI flag > env var > config file > default precedence. The env var is already folded into cli_host by clap’s env attribute on TuneArgs::bridge_host/OpcCommand’s per-variant bridge_host.
resolve_config_store_path
Resolve which path the TOML config store should use: an explicit --config path if one was provided, otherwise the platform-default bhtune.toml location from config_path_from. Explicit paths must already exist; an auto-discovered missing file is acceptable and can be created on first save.
resolve_db_path
Resolve the database path with CLI flag > env var > config file > platform default precedence. The env var is already folded into cli_db by clap’s env attribute on Cli::db; the platform-default tier takes its own raw environment values (rather than reading std::env internally, like default_db_path_from) so this stays fully unit-testable without touching real process environment variables.
resolve_demo_policy
resolve_demo_policy_from_config
resolve_origin
resolve_retention_days
Resolve the history retention policy (history-retention) with CLI flag > env var > config file > default precedence, matching resolve_bridge_host’s shape. The env var is already folded into cli_days by clap’s env attribute on Cli::retention_days. None means retain forever – there is no built-in default number of days; see BhtuneConfig::retention_days for why.
resolve_server
Resolve the OPC DA server ProgID with CLI flag > config file precedence, erroring if neither is set – there’s no sensible default for which OPC server to talk to.
resolve_server_mode
resolve_tuning_config
Resolve optional [tuning] values against the built-in defaults.
save_config_store
Safely save the two config-page-managed settings with optimistic-concurrency checks.
templates_path_from
Derive bhtune’s default user template catalog location the same way config_path_from derives bhtune.toml’s – deliberately the same directory, since both are per-user settings a site admin edits by hand, not persistent application data (contrast default_db_path_from/default_log_dir_from, which live under the platform data directory instead). See load_user_templates for how this default fits into the full template-user-catalog precedence chain.
tuning_config_sources
Report whether each effective tuning value came from TOML or a built-in default.
validate_demo_origin
Validates the exact browser origin used by a public Demo deployment.
validate_demo_trusted_proxy
Validates a trusted reverse-proxy address before Demo requests may use forwarded client IPs.
validate_tuning_config
Validate concrete tuning timing values.