AppState

Struct AppState 

Source
pub struct AppState {
    pub vanguard_state: VanguardState,
    pub bandwidth_stats: BandwidthStats,
    pub timeout_stats: TimeoutStats,
    pub logguard: Option<LogGuard>,
    pub pathverify: Option<PathVerify>,
    pub config: Config,
}
Expand description

Application state shared across event handlers.

AppState aggregates all the stateful components needed during the main event loop. It is passed to event handlers to allow them to update their respective state and access configuration.

§Components

┌─────────────────────────────────────────────┐
│                  AppState                   │
│                                             │
│  ┌─────────────────┐  ┌─────────────────┐   │
│  │ VanguardState   │  │ BandwidthStats  │   │
│  │ • layer2 guards │  │ • circuit stats │   │
│  │ • layer3 guards │  │ • conn tracking │   │
│  │ • rendguard     │  │ • attack detect │   │
│  └─────────────────┘  └─────────────────┘   │
│                                             │
│  ┌─────────────────┐  ┌─────────────────┐   │
│  │ TimeoutStats    │  │ LogGuard        │   │
│  │ • CBT tracking  │  │ • log buffering │   │
│  │ • timeout rates │  │ • warn detection│   │
│  └─────────────────┘  └─────────────────┘   │
│                                             │
│  ┌─────────────────┐  ┌─────────────────┐   │
│  │ PathVerify      │  │ Config          │   │
│  │ • path checking │  │ • all settings  │   │
│  │ • guard verify  │  │ • thresholds    │   │
│  └─────────────────┘  └─────────────────┘   │
└────────────────────────────────────────────┘

§Thread Safety

AppState is not thread-safe. It is designed to be used within a single async task (the main event loop). For concurrent access, wrap in appropriate synchronization primitives.

§Example

use vanguards_rs::control::AppState;
use vanguards_rs::vanguards::VanguardState;
use vanguards_rs::config::Config;

// Create state for the event loop
let vanguard_state = VanguardState::new("/var/lib/tor/vanguards.state");
let config = Config::default();
let app_state = AppState::new(vanguard_state, config);

§See Also

Fields§

§vanguard_state: VanguardState

Vanguard state containing guard layers and rendguard.

§bandwidth_stats: BandwidthStats

Bandwidth statistics for attack detection.

§timeout_stats: TimeoutStats

Circuit build timeout statistics.

§logguard: Option<LogGuard>

Optional log guard for log buffering and analysis.

§pathverify: Option<PathVerify>

Optional path verifier for circuit path validation.

§config: Config

Application configuration.

Implementations§

Source§

impl AppState

Source

pub fn new(vanguard_state: VanguardState, config: Config) -> Self

Creates a new application state with the given vanguard state and configuration.

Initializes bandwidth and timeout statistics to empty state. LogGuard and PathVerify are initialized later in the control loop based on configuration.

§Arguments
  • vanguard_state - The vanguard state (loaded from file or newly created)
  • config - The application configuration
§Returns

A new AppState with initialized statistics and the provided state/config.

§Example
use vanguards_rs::control::AppState;
use vanguards_rs::vanguards::VanguardState;
use vanguards_rs::config::Config;

let state = VanguardState::new("/tmp/vanguards.state");
let config = Config::default();
let app_state = AppState::new(state, config);

Auto Trait Implementations§

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> 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, 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