tuwunel_admin/debug/mod.rs
1mod change_log_level;
2mod create_jwt;
3mod database_files;
4mod database_stats;
5mod dump_pdus;
6mod echo;
7mod event_fetcher;
8mod first_pdu_in_room;
9mod force_device_list_updates;
10mod force_set_room_state_from_server;
11mod get_auth_chain;
12mod get_pdu;
13mod get_remote_pdu;
14mod get_remote_pdu_list;
15mod get_retained_pdu;
16mod get_room_state;
17mod get_short_pdu;
18mod get_signing_keys;
19mod get_verify_keys;
20mod latest_pdu_in_room;
21mod list_dependencies;
22mod memory_stats;
23mod parse_pdu;
24mod ping;
25mod resolve_true_destination;
26mod resync_database;
27mod runtime_interval;
28mod runtime_metrics;
29mod sign_json;
30mod task_interval;
31mod task_metrics;
32pub(crate) mod tester;
33mod time;
34mod trim_memory;
35mod verify_json;
36mod verify_pdu;
37
38use clap::Subcommand;
39use ruma::{OwnedEventId, OwnedRoomId, OwnedRoomOrAliasId, OwnedServerName};
40use tuwunel_core::Result;
41use tuwunel_service::rooms::short::ShortRoomId;
42
43use self::{event_fetcher::EventFetcherCommand, tester::TesterCommand};
44use crate::admin_command_dispatch;
45
46#[admin_command_dispatch]
47#[derive(Debug, Subcommand)]
48pub(super) enum DebugCommand {
49 /// - Echo input of admin command
50 Echo {
51 message: Vec<String>,
52 },
53
54 /// - Get the auth_chain of a PDU
55 GetAuthChain {
56 /// An event ID (the $ character followed by the base64 reference hash)
57 event_id: OwnedEventId,
58 },
59
60 /// - Parse and print a PDU from a JSON
61 ///
62 /// The PDU event is only checked for validity and is not added to the
63 /// database.
64 ///
65 /// This command needs a JSON blob provided in a Markdown code block below
66 /// the command.
67 ParsePdu,
68
69 /// - Retrieve and print a PDU by EventID from the tuwunel database
70 GetPdu {
71 /// An event ID (a $ followed by the base64 reference hash)
72 event_id: OwnedEventId,
73 },
74
75 /// - Retrieve and print a PDU by PduId from the tuwunel database
76 GetShortPdu {
77 /// Shortroomid integer
78 shortroomid: ShortRoomId,
79
80 /// PduCount integer
81 count: i64,
82 },
83
84 /// - Attempts to retrieve a PDU from a remote server. Inserts it into our
85 /// database/timeline if found and we do not have this PDU already
86 /// (following normal event auth rules, handles it as an incoming PDU).
87 GetRemotePdu {
88 /// An event ID (a $ followed by the base64 reference hash)
89 event_id: OwnedEventId,
90
91 /// Argument for us to attempt to fetch the event from the
92 /// specified remote server.
93 server: OwnedServerName,
94 },
95
96 /// - Same as `get-remote-pdu` but accepts a codeblock newline delimited
97 /// list of PDUs and a single server to fetch from
98 GetRemotePduList {
99 /// Argument for us to attempt to fetch all the events from the
100 /// specified remote server.
101 server: OwnedServerName,
102
103 /// If set, ignores errors, else stops at the first error/failure.
104 #[arg(short, long)]
105 force: bool,
106 },
107
108 /// - Gets all the room state events for the specified room.
109 GetRoomState {
110 /// Room ID
111 room_id: OwnedRoomOrAliasId,
112
113 /// Event Type
114 kind: Option<String>,
115
116 /// State Key
117 state_key: Option<String>,
118 },
119
120 /// - Get and display signing keys from local cache or remote server.
121 GetSigningKeys {
122 server_name: Option<OwnedServerName>,
123
124 #[arg(long)]
125 notary: Option<OwnedServerName>,
126
127 #[arg(short, long)]
128 query: bool,
129 },
130
131 /// - Get and display signing keys from local cache or remote server.
132 GetVerifyKeys {
133 server_name: Option<OwnedServerName>,
134 },
135
136 /// - Sends a federation request to the remote server's
137 /// `/_matrix/federation/v1/version` endpoint and measures the latency it
138 /// took for the server to respond
139 Ping {
140 server: OwnedServerName,
141 },
142
143 /// - Forces device lists for all local and remote users to be updated (as
144 /// having new keys available)
145 ForceDeviceListUpdates,
146
147 /// - Change tracing log level/filter on the fly
148 ///
149 /// This accepts the same format as the `log` config option.
150 ChangeLogLevel {
151 /// Log level/filter
152 filter: Option<String>,
153
154 /// Resets the log level/filter to the one in your config
155 #[arg(short, long)]
156 reset: bool,
157 },
158
159 /// - Sign JSON blob
160 ///
161 /// This command needs a JSON blob provided in a Markdown code block below
162 /// the command.
163 SignJson,
164
165 /// - Verify JSON signatures
166 ///
167 /// This command needs a JSON blob provided in a Markdown code block below
168 /// the command.
169 VerifyJson,
170
171 /// - Verify PDU
172 ///
173 /// This re-verifies a PDU existing in the database found by ID.
174 VerifyPdu {
175 event_id: OwnedEventId,
176 },
177
178 /// - Prints the very first PDU in the specified room (typically
179 /// m.room.create)
180 FirstPduInRoom {
181 /// The room ID
182 room_id: OwnedRoomId,
183 },
184
185 /// - Prints the latest ("last") PDU in the specified room (typically a
186 /// message)
187 LatestPduInRoom {
188 /// The room ID
189 room_id: OwnedRoomId,
190 },
191
192 /// - Forcefully replaces the room state of our local copy of the specified
193 /// room, with the copy (auth chain and room state events) the specified
194 /// remote server says.
195 ///
196 /// A common desire for room deletion is to simply "reset" our copy of the
197 /// room. While this admin command is not a replacement for that, if you
198 /// know you have split/broken room state and you know another server in the
199 /// room that has the best/working room state, this command can let you use
200 /// their room state. Such example is your server saying users are in a
201 /// room, but other servers are saying they're not in the room in question.
202 ///
203 /// This command will get the latest PDU in the room we know about, and
204 /// request the room state at that point in time via
205 /// `/_matrix/federation/v1/state/{roomId}`.
206 ForceSetRoomStateFromServer {
207 /// The impacted room ID
208 room_id: OwnedRoomId,
209 /// The server we will use to query the room state for
210 server_name: OwnedServerName,
211 },
212
213 /// - Runs a server name through tuwunel's true destination resolution
214 /// process
215 ///
216 /// Useful for debugging well-known issues
217 ResolveTrueDestination {
218 server_name: OwnedServerName,
219
220 #[arg(short, long)]
221 no_cache: bool,
222 },
223
224 /// - Print extended memory usage
225 ///
226 /// Optional argument is a character mask (a sequence of characters in any
227 /// order) which enable additional extended statistics. Known characters are
228 /// "abdeglmx". For convenience, a '*' will enable everything.
229 MemoryStats {
230 opts: Option<String>,
231 },
232
233 /// - Print general tokio runtime metric totals.
234 RuntimeMetrics,
235
236 /// - Print detailed tokio runtime metrics accumulated since last command
237 /// invocation.
238 RuntimeInterval,
239
240 /// - Print detailed tokio task metrics accumulated in total.
241 TaskMetrics,
242
243 /// - Print detailed tokio task metrics accumulated since last command
244 /// invocation.
245 TaskInterval,
246
247 /// - Print the current time
248 Time,
249
250 /// - List dependencies
251 ListDependencies {
252 #[arg(short, long)]
253 names: bool,
254 },
255
256 /// - Get database statistics
257 DatabaseStats {
258 property: Option<String>,
259
260 #[arg(short, long, alias("column"))]
261 map: Option<String>,
262 },
263
264 /// - Trim memory usage
265 TrimMemory,
266
267 /// - List database files
268 DatabaseFiles {
269 map: Option<String>,
270
271 #[arg(long)]
272 level: Option<i32>,
273 },
274
275 /// - Create a JWT token for login
276 CreateJwt {
277 /// Localpart of the user's MXID
278 user: String,
279
280 /// Set expiration time in seconds from now.
281 #[arg(long)]
282 exp_from_now: Option<u64>,
283
284 /// Set not-before time in seconds from now.
285 #[arg(long)]
286 nbf_from_now: Option<u64>,
287
288 /// Claim an issuer.
289 #[arg(long)]
290 issuer: Option<String>,
291
292 /// Claim an audience.
293 #[arg(long)]
294 audience: Option<String>,
295 },
296
297 /// - Synchronize database with primary (secondary only)
298 ResyncDatabase,
299
300 /// - Retrieves the saved original PDU before it has been redacted
301 GetRetainedPdu {
302 event_id: OwnedEventId,
303 },
304
305 /// - Dump all stored PDUs
306 DumpPdus {
307 dir: String,
308 },
309
310 /// - Drive the federation event-fetcher service directly (diagnostic)
311 #[command(subcommand)]
312 EventFetcher(EventFetcherCommand),
313
314 /// - Developer test stubs
315 #[command(subcommand)]
316 #[clap(hide(true))]
317 Tester(TesterCommand),
318}