Config

Struct Config 

Source
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

FieldTypeDefaultDescription
control_ipString"127.0.0.1"Tor control port IP address
control_portOption<u16>NoneTor control port number
control_socketOption<PathBuf>NoneUnix socket path (alternative to TCP)
control_passOption<String>NoneControl port password

§File Settings

FieldTypeDefaultDescription
state_filePathBuf"vanguards.state"Vanguard state persistence file

§Logging Settings

FieldTypeDefaultDescription
loglevelLogLevelNoticeLog verbosity level
logfileOption<String>NoneLog destination (file, :syslog:, or stdout)

§Component Toggles

FieldTypeDefaultDescription
enable_vanguardsbooltrueEnable vanguard selection
enable_bandguardsbooltrueEnable bandwidth monitoring
enable_rendguardbooltrueEnable rendezvous point monitoring
enable_logguardbooltrueEnable log monitoring
enable_cbtverifyboolfalseEnable circuit build timeout verification
enable_pathverifyboolfalseEnable path verification

§Operational Settings

FieldTypeDefaultDescription
close_circuitsbooltrueClose circuits on detected attacks
one_shot_vanguardsboolfalseSet vanguards and exit immediately
retry_limitOption<u32>NoneMax 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

Fields§

§control_ip: String

IP 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: PathBuf

Path to the vanguard state file.

§loglevel: LogLevel

Log 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: bool

Set vanguards and exit immediately.

§close_circuits: bool

Close circuits on detected attacks.

§enable_vanguards: bool

Enable vanguard selection.

§enable_bandguards: bool

Enable bandwidth monitoring.

§enable_rendguard: bool

Enable rendezvous point monitoring.

§enable_logguard: bool

Enable log monitoring.

§enable_cbtverify: bool

Enable circuit build timeout verification.

§enable_pathverify: bool

Enable path verification.

§vanguards: VanguardsConfig

Vanguard-specific configuration.

§bandguards: BandguardsConfig

Bandwidth monitoring configuration.

§rendguard: RendguardConfig

Rendezvous point monitoring configuration.

§logguard: LogguardConfig

Log monitoring configuration.

Implementations§

Source§

impl Config

Source

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.

Source

pub fn to_toml(&self) -> Result<String>

Serialize configuration to TOML string.

§Errors

Returns Error::Config if serialization fails.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,