pub async fn run_main(config: Config) -> Result<()>Expand description
Runs the main application loop with reconnection support.
This is the primary entry point for the vanguards application. It manages the complete lifecycle including connection, reconnection, and graceful shutdown.
§Lifecycle
┌─────────────────────────────────────────────────────────────┐
│ run_main() │
│ │
│ 1. Set up CTRL+C handler │
│ 2. Load/create vanguard state │
│ 3. Enter reconnection loop: │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ • Check shutdown flag │ │
│ │ • Check retry limit │ │
│ │ • Run control_loop() │ │
│ │ • Log disconnection │ │
│ │ • Wait 1 second │ │
│ │ • Increment reconnect counter │ │
│ └─────────────────────────────────────────────────────┘ │
│ 4. Exit when shutdown or retry limit reached │
└─────────────────────────────────────────────────────────────┘§Arguments
config- The application configuration
§Returns
Returns Ok(()) on graceful shutdown, or an error if the application
fails to start or encounters an unrecoverable error.
§Errors
Returns Error::Config if:
- Failed to connect to Tor after all retry attempts
- Invalid configuration values
§Shutdown Behavior
The function handles graceful shutdown via:
- CTRL+C signal (sets shutdown flag)
- Retry limit reached (configurable via
config.retry_limit)
§Example
use vanguards_rs::config::Config;
use vanguards_rs::control::run_main;
#[tokio::main]
async fn main() -> Result<(), vanguards_rs::error::Error> {
// Load configuration from file or use defaults
let config = Config::default();
// Run until shutdown signal or error
run_main(config).await
}§See Also
control_loop- The inner event processing loopConfig- Configuration optionsVanguardState- State persistence