1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
//! vanguards-rs CLI application entry point.
//!
//! This binary provides a command-line interface for running vanguards-rs
//! as a standalone application to protect Tor hidden services.
//!
//! # Overview
//!
//! The vanguards-rs CLI is the primary way to run vanguards protection for
//! Tor hidden services. It handles configuration loading, logging setup,
//! and runs the main protection loop.
//!
//! # Startup Flow
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ vanguards-rs Startup Flow │
//! └─────────────────────────────────────────────────────────────────┘
//!
//! ┌─────────────────┐
//! │ Parse CLI Args │ ◄── clap parses command-line arguments
//! └────────┬────────┘
//! │
//! ▼
//! ┌─────────────────┐ ┌─────────────────┐
//! │ --generate_config│────▶│ Write default │────▶ Exit
//! │ specified? │ │ config & exit │
//! └────────┬────────┘ └─────────────────┘
//! │ No
//! ▼
//! ┌─────────────────┐
//! │ Load Config │ ◄── Defaults → File → CLI → Env
//! └────────┬────────┘
//! │
//! ▼
//! ┌─────────────────┐
//! │ Initialize │ ◄── Set up tracing subscriber
//! │ Logging │
//! └────────┬────────┘
//! │
//! ▼
//! ┌─────────────────┐
//! │ Log Startup │ ◄── Version, config, enabled components
//! │ Info │
//! └────────┬────────┘
//! │
//! ▼
//! ┌─────────────────┐
//! │ Run Main Loop │ ◄── control::run_main()
//! │ (control.rs) │
//! └────────┬────────┘
//! │
//! ▼
//! ┌─────────────────┐
//! │ Exit with │
//! │ status code │
//! └─────────────────┘
//! ```
//!
//! # Usage Examples
//!
//! ## Basic Usage
//!
//! ```bash
//! # Run with default settings (connects to 127.0.0.1:9051)
//! vanguards-rs
//!
//! # Connect to specific control port
//! vanguards-rs --control-ip 127.0.0.1 --control-port 9051
//!
//! # Connect via Unix socket
//! vanguards-rs --control-socket /run/tor/control
//! ```
//!
//! ## Configuration
//!
//! ```bash
//! # Generate default configuration file
//! vanguards-rs --generate_config vanguards.conf
//!
//! # Use custom configuration file
//! vanguards-rs --config /etc/vanguards/vanguards.conf
//!
//! # Override config with CLI arguments
//! vanguards-rs --config vanguards.conf --loglevel DEBUG
//! ```
//!
//! ## State Management
//!
//! ```bash
//! # Use custom state file
//! vanguards-rs --state /var/lib/tor/vanguards.state
//!
//! # One-shot mode: set vanguards and exit
//! vanguards-rs --one-shot-vanguards
//! ```
//!
//! ## Component Control
//!
//! ```bash
//! # Disable specific components
//! vanguards-rs --disable-bandguards --disable-logguard
//!
//! # Enable optional components
//! vanguards-rs --enable-cbtverify --enable-pathverify
//! ```
//!
//! ## Logging
//!
//! ```bash
//! # Set log level
//! vanguards-rs --loglevel DEBUG
//!
//! # Log to file
//! vanguards-rs --logfile /var/log/vanguards.log
//!
//! # Log to syslog
//! vanguards-rs --logfile :syslog:
//! ```
//!
//! # Exit Codes
//!
//! | Code | Meaning |
//! |------|---------|
//! | 0 | Success |
//! | 1 | Error (see stderr for details) |
//!
//! # Environment Variables
//!
//! | Variable | Description |
//! |----------|-------------|
//! | `VANGUARDS_STATE` | Path to state file (equivalent to `--state`) |
//! | `VANGUARDS_CONFIG` | Path to config file (equivalent to `--config`) |
//!
//! # See Also
//!
//! - [`CliArgs`](crate::CliArgs) - Command-line argument definitions
//! - [`Config`](crate::Config) - Configuration structure
//! - [`control::run_main`](crate::control::run_main) - Main event loop
use Parser;
use ExitCode;
use ;
async
async