1use {
2 app::{
3 log::command::logger_service_client::LoggerServiceClient,
4 proxyman::command::handler_service_client::HandlerServiceClient,
5 router::command::routing_service_client::RoutingServiceClient,
6 stats::command::stats_service_client::StatsServiceClient,
7 },
8 core::observatory::command::observatory_service_client::ObservatoryServiceClient,
9 tonic::transport::{Channel, Error},
10 transport::internet::grpc::grpc_service_client::GrpcServiceClient,
11};
12
13pub use prost_types;
14pub use tonic;
15
16pub mod app {
17 pub mod commander {
18 tonic::include_proto!("xray.app.commander");
19 }
20
21 pub mod dispatcher {
22 tonic::include_proto!("xray.app.dispatcher");
23 }
24
25 pub mod dns {
27 tonic::include_proto!("xray.app.dns");
28
29 pub mod fakedns {
31 tonic::include_proto!("xray.app.dns.fakedns");
32 }
33 }
34
35 pub mod log {
37 tonic::include_proto!("xray.app.log");
38
39 #[cfg(feature = "client")]
40 pub mod command {
41 tonic::include_proto!("xray.app.log.command");
42 }
43 }
44
45 pub mod metrics {
47 tonic::include_proto!("xray.app.metrics");
48 }
49
50 pub mod policy {
52 tonic::include_proto!("xray.app.policy");
53 }
54
55 pub mod proxyman {
56 tonic::include_proto!("xray.app.proxyman");
57
58 #[cfg(feature = "client")]
59 pub mod command {
60 tonic::include_proto!("xray.app.proxyman.command");
61 }
62 }
63
64 pub mod reverse {
66 tonic::include_proto!("xray.app.reverse");
67 }
68
69 pub mod router {
71 tonic::include_proto!("xray.app.router");
72
73 #[cfg(feature = "client")]
74 pub mod command {
75 tonic::include_proto!("xray.app.router.command");
76 }
77 }
78
79 pub mod stats {
81 tonic::include_proto!("xray.app.stats");
82
83 #[cfg(feature = "client")]
84 pub mod command {
85 tonic::include_proto!("xray.app.stats.command");
86 }
87 }
88}
89
90pub mod common {
91 pub mod log {
92 tonic::include_proto!("xray.common.log");
93 }
94
95 pub mod net {
96 tonic::include_proto!("xray.common.net");
97 }
98
99 pub mod protocol {
100 tonic::include_proto!("xray.common.protocol");
101 }
102
103 pub mod serial {
104 tonic::include_proto!("xray.common.serial");
105 }
106}
107
108pub mod core {
110 tonic::include_proto!("xray.core");
111
112 pub mod observatory {
114 tonic::include_proto!("xray.core.app.observatory");
115
116 pub mod burst {
117 tonic::include_proto!("xray.core.app.observatory.burst");
118 }
119
120 #[cfg(feature = "client")]
121 pub mod command {
122 tonic::include_proto!("xray.core.app.observatory.command");
123 }
124 }
125}
126
127pub mod proxy {
128 pub mod blackhole {
130 tonic::include_proto!("xray.proxy.blackhole");
131 }
132
133 pub mod dns {
135 tonic::include_proto!("xray.proxy.dns");
136 }
137
138 pub mod dokodemo {
140 tonic::include_proto!("xray.proxy.dokodemo");
141 }
142
143 pub mod freedom {
145 tonic::include_proto!("xray.proxy.freedom");
146 }
147
148 pub mod http {
151 tonic::include_proto!("xray.proxy.http");
152 }
153
154 pub mod loopback {
156 tonic::include_proto!("xray.proxy.loopback");
157 }
158
159 pub mod shadowsocks {
162 tonic::include_proto!("xray.proxy.shadowsocks");
163 }
164
165 pub mod shadowsocks_2022 {
168 tonic::include_proto!("xray.proxy.shadowsocks_2022");
169 }
170
171 pub mod socks {
174 tonic::include_proto!("xray.proxy.socks");
175 }
176
177 pub mod trojan {
180 tonic::include_proto!("xray.proxy.trojan");
181 }
182
183 pub mod vless {
185 tonic::include_proto!("xray.proxy.vless");
186
187 pub mod encoding {
188 tonic::include_proto!("xray.proxy.vless.encoding");
189 }
190
191 pub mod inbound {
193 tonic::include_proto!("xray.proxy.vless.inbound");
194 }
195
196 pub mod outbound {
198 tonic::include_proto!("xray.proxy.vless.outbound");
199 }
200 }
201
202 pub mod vmess {
204 tonic::include_proto!("xray.proxy.vmess");
205
206 pub mod inbound {
208 tonic::include_proto!("xray.proxy.vmess.inbound");
209 }
210
211 pub mod outbound {
213 tonic::include_proto!("xray.proxy.vmess.outbound");
214 }
215 }
216
217 pub mod wireguard {
220 tonic::include_proto!("xray.proxy.wireguard");
221 }
222}
223
224
225pub mod transport {
226 pub mod internet {
227 tonic::include_proto!("xray.transport.internet");
228
229 pub mod grpc {
231 tonic::include_proto!("xray.transport.internet.grpc.encoding");
232 }
233
234 pub mod httpupgrade {
236 tonic::include_proto!("xray.transport.internet.httpupgrade");
237 }
238
239 pub mod kcp {
241 tonic::include_proto!("xray.transport.internet.kcp");
242 }
243
244 pub mod quic {
245 }
247
248 pub mod reality {
249 tonic::include_proto!("xray.transport.internet.reality");
250 }
251
252 pub mod splithttp {
254 tonic::include_proto!("xray.transport.internet.splithttp");
255 }
256
257 pub mod tcp {
259 tonic::include_proto!("xray.transport.internet.tcp");
260 }
261
262 pub mod tls {
264 tonic::include_proto!("xray.transport.internet.tls");
265 }
266
267 pub mod udp {
268 tonic::include_proto!("xray.transport.internet.udp");
269 }
270
271 pub mod websocket {
273 tonic::include_proto!("xray.transport.internet.websocket");
274 }
275
276 pub mod headers {
277 pub mod dns {
278 tonic::include_proto!("xray.transport.internet.headers.dns");
279 }
280
281 pub mod http {
282 tonic::include_proto!("xray.transport.internet.headers.http");
283 }
284
285 pub mod noop {
286 tonic::include_proto!("xray.transport.internet.headers.noop");
287 }
288
289 pub mod srtp {
290 tonic::include_proto!("xray.transport.internet.headers.srtp");
291 }
292
293 pub mod tls {
294 tonic::include_proto!("xray.transport.internet.headers.tls");
295 }
296
297 pub mod utp {
298 tonic::include_proto!("xray.transport.internet.headers.utp");
299 }
300
301 pub mod wechat {
302 tonic::include_proto!("xray.transport.internet.headers.wechat");
303 }
304
305 pub mod wireguard {
306 tonic::include_proto!("xray.transport.internet.headers.wireguard");
307 }
308 }
309 }
310}
311
312#[cfg(feature = "connect")]
316pub async fn connect<S: AsRef<str>>(path: S) -> Result<Channel, Error> {
317 use tonic::transport::Endpoint;
318
319 let path = path.as_ref();
320
321 let channel = Endpoint::try_from(format!("https://{path}"))?
322 .connect()
323 .await?;
324
325 Ok(channel)
326}
327
328#[cfg(feature = "client")]
330pub struct Client {
331 channel: Channel,
332}
333
334#[cfg(feature = "client")]
335impl Client {
336 #[cfg(feature = "connect")]
337 pub async fn from_url<S: AsRef<str>>(url: S) -> Result<Self, Error> {
338 let channel = connect(url).await?;
339 Ok(Self { channel })
340 }
341
342 #[inline]
343 pub fn logger(&self) -> LoggerServiceClient<Channel> {
344 LoggerServiceClient::new(self.channel.clone())
345 }
346
347 #[inline]
348 pub fn handler(&self) -> HandlerServiceClient<Channel> {
349 HandlerServiceClient::new(self.channel.clone())
350 }
351
352 #[inline]
353 pub fn routing(&self) -> RoutingServiceClient<Channel> {
354 RoutingServiceClient::new(self.channel.clone())
355 }
356
357 #[inline]
358 pub fn stats(&self) -> StatsServiceClient<Channel> {
359 StatsServiceClient::new(self.channel.clone())
360 }
361
362 #[inline]
363 pub fn observatory(&self) -> ObservatoryServiceClient<Channel> {
364 ObservatoryServiceClient::new(self.channel.clone())
365 }
366
367 #[inline]
368 pub fn grpc(&self) -> GrpcServiceClient<Channel> {
369 GrpcServiceClient::new(self.channel.clone())
370 }
371}
372
373#[cfg(test)]
374mod tests {
375 use prost_types::Any;
376 use crate::app::proxyman::InboundConfig;
377
378 #[test]
379 fn any_roundtrip() {
380 let original = InboundConfig {};
381
382 let any = Any::from_msg(&original).expect("should not fail to encode");
383 let decoded: InboundConfig = any.to_msg().expect("should not fail to decode");
384
385 assert_eq!(original, decoded)
386 }
387}