Skip to main content

tuwunel_admin/debug/
mod.rs

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