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
VanguardState- Guard layer managementBandwidthStats- Bandwidth attack detectionTimeoutStats- Circuit build timeout verificationLogGuard- Log buffering and analysisPathVerify- Circuit path verification
Fields§
§vanguard_state: VanguardStateVanguard state containing guard layers and rendguard.
bandwidth_stats: BandwidthStatsBandwidth statistics for attack detection.
timeout_stats: TimeoutStatsCircuit 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: ConfigApplication configuration.
Implementations§
Source§impl AppState
impl AppState
Sourcepub fn new(vanguard_state: VanguardState, config: Config) -> Self
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);