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