pub struct Config {Show 20 fields
pub control_ip: String,
pub control_port: Option<u16>,
pub control_socket: Option<PathBuf>,
pub control_pass: Option<String>,
pub state_file: PathBuf,
pub loglevel: LogLevel,
pub logfile: Option<String>,
pub retry_limit: Option<u32>,
pub one_shot_vanguards: bool,
pub close_circuits: bool,
pub enable_vanguards: bool,
pub enable_bandguards: bool,
pub enable_rendguard: bool,
pub enable_logguard: bool,
pub enable_cbtverify: bool,
pub enable_pathverify: bool,
pub vanguards: VanguardsConfig,
pub bandguards: BandguardsConfig,
pub rendguard: RendguardConfig,
pub logguard: LogguardConfig,
}Expand description
Main configuration struct for vanguards-rs.
This struct contains all configuration options for the vanguards-rs library and CLI application. Configuration can be loaded from TOML files, command-line arguments, and environment variables.
§Fields Overview
§Connection Settings
| Field | Type | Default | Description |
|---|---|---|---|
control_ip | String | "127.0.0.1" | Tor control port IP address |
control_port | Option<u16> | None | Tor control port number |
control_socket | Option<PathBuf> | None | Unix socket path (alternative to TCP) |
control_pass | Option<String> | None | Control port password |
§File Settings
| Field | Type | Default | Description |
|---|---|---|---|
state_file | PathBuf | "vanguards.state" | Vanguard state persistence file |
§Logging Settings
| Field | Type | Default | Description |
|---|---|---|---|
loglevel | LogLevel | Notice | Log verbosity level |
logfile | Option<String> | None | Log destination (file, :syslog:, or stdout) |
§Component Toggles
| Field | Type | Default | Description |
|---|---|---|---|
enable_vanguards | bool | true | Enable vanguard selection |
enable_bandguards | bool | true | Enable bandwidth monitoring |
enable_rendguard | bool | true | Enable rendezvous point monitoring |
enable_logguard | bool | true | Enable log monitoring |
enable_cbtverify | bool | false | Enable circuit build timeout verification |
enable_pathverify | bool | false | Enable path verification |
§Operational Settings
| Field | Type | Default | Description |
|---|---|---|---|
close_circuits | bool | true | Close circuits on detected attacks |
one_shot_vanguards | bool | false | Set vanguards and exit immediately |
retry_limit | Option<u32> | None | Max reconnection attempts (None = infinite) |
§Example
§Creating Default Configuration
use vanguards_rs::Config;
let config = Config::default();
assert_eq!(config.control_ip, "127.0.0.1");
assert!(config.enable_vanguards);§Loading from File
use vanguards_rs::Config;
use std::path::Path;
let config = Config::from_file(Path::new("vanguards.conf"))?;§Programmatic Configuration
use vanguards_rs::{Config, LogLevel};
use std::path::PathBuf;
let mut config = Config::default();
config.control_port = Some(9051);
config.loglevel = LogLevel::Debug;
config.state_file = PathBuf::from("/var/lib/tor/vanguards.state");
config.enable_cbtverify = true;
// Validate before use
config.validate().expect("Invalid configuration");§Validation
Call validate() to check configuration consistency:
- Layer lifetime ranges must be valid (min ≤ max)
- Ratio values must be positive
- Churn values must be non-negative
§See Also
VanguardsConfig- Vanguard-specific settingsBandguardsConfig- Bandwidth monitoring settingsRendguardConfig- Rendezvous point monitoring settingsLogguardConfig- Log monitoring settingsCliArgs- Command-line argument parsingload_config- Configuration loading function
Fields§
§control_ip: StringIP address of the Tor control port.
control_port: Option<u16>Port number of the Tor control port.
control_socket: Option<PathBuf>Path to the Tor control socket.
control_pass: Option<String>Password for Tor control authentication.
state_file: PathBufPath to the vanguard state file.
loglevel: LogLevelLog level for output.
logfile: Option<String>Log file path. None for stdout, “:syslog:” for syslog.
retry_limit: Option<u32>Maximum reconnection attempts. None for infinite.
one_shot_vanguards: boolSet vanguards and exit immediately.
close_circuits: boolClose circuits on detected attacks.
enable_vanguards: boolEnable vanguard selection.
enable_bandguards: boolEnable bandwidth monitoring.
enable_rendguard: boolEnable rendezvous point monitoring.
enable_logguard: boolEnable log monitoring.
enable_cbtverify: boolEnable circuit build timeout verification.
enable_pathverify: boolEnable path verification.
vanguards: VanguardsConfigVanguard-specific configuration.
bandguards: BandguardsConfigBandwidth monitoring configuration.
rendguard: RendguardConfigRendezvous point monitoring configuration.
logguard: LogguardConfigLog monitoring configuration.
Implementations§
Source§impl Config
impl Config
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Load configuration from a TOML file.
§Errors
Returns Error::Io if the file cannot be read.
Returns Error::Config if the TOML is invalid.
Sourcepub fn validate(&self) -> Result<()>
pub fn validate(&self) -> Result<()>
Validate configuration values.
Checks that all configuration values are within acceptable ranges and that required fields are present.
§Errors
Returns Error::Config if validation fails.
Sourcepub fn resolve_control_ip(&mut self) -> Result<()>
pub fn resolve_control_ip(&mut self) -> Result<()>
Resolve hostname to IP address if control_ip is a domain name.
§Errors
Returns Error::Config if hostname resolution fails.