use {
app::{
log::command::logger_service_client::LoggerServiceClient,
proxyman::command::handler_service_client::HandlerServiceClient,
router::command::routing_service_client::RoutingServiceClient,
stats::command::stats_service_client::StatsServiceClient,
},
core::observatory::command::observatory_service_client::ObservatoryServiceClient,
tonic::transport::{Channel, Error},
transport::internet::grpc::grpc_service_client::GrpcServiceClient,
};
pub use prost_types;
pub use tonic;
pub mod app {
pub mod commander {
tonic::include_proto!("xray.app.commander");
}
pub mod dispatcher {
tonic::include_proto!("xray.app.dispatcher");
}
pub mod dns {
tonic::include_proto!("xray.app.dns");
pub mod fakedns {
tonic::include_proto!("xray.app.dns.fakedns");
}
}
pub mod log {
tonic::include_proto!("xray.app.log");
#[cfg(feature = "client")]
pub mod command {
tonic::include_proto!("xray.app.log.command");
}
}
pub mod metrics {
tonic::include_proto!("xray.app.metrics");
}
pub mod policy {
tonic::include_proto!("xray.app.policy");
}
pub mod proxyman {
tonic::include_proto!("xray.app.proxyman");
#[cfg(feature = "client")]
pub mod command {
tonic::include_proto!("xray.app.proxyman.command");
}
}
pub mod reverse {
tonic::include_proto!("xray.app.reverse");
}
pub mod router {
tonic::include_proto!("xray.app.router");
#[cfg(feature = "client")]
pub mod command {
tonic::include_proto!("xray.app.router.command");
}
}
pub mod stats {
tonic::include_proto!("xray.app.stats");
#[cfg(feature = "client")]
pub mod command {
tonic::include_proto!("xray.app.stats.command");
}
}
}
pub mod common {
pub mod log {
tonic::include_proto!("xray.common.log");
}
pub mod net {
tonic::include_proto!("xray.common.net");
}
pub mod protocol {
tonic::include_proto!("xray.common.protocol");
}
pub mod serial {
tonic::include_proto!("xray.common.serial");
}
}
pub mod core {
tonic::include_proto!("xray.core");
pub mod observatory {
tonic::include_proto!("xray.core.app.observatory");
#[cfg(feature = "client")]
pub mod command {
tonic::include_proto!("xray.core.app.observatory.command");
}
}
}
pub mod proxy {
pub mod blackhole {
tonic::include_proto!("xray.proxy.blackhole");
}
pub mod dns {
tonic::include_proto!("xray.proxy.dns");
}
pub mod dokodemo {
tonic::include_proto!("xray.proxy.dokodemo");
}
pub mod freedom {
tonic::include_proto!("xray.proxy.freedom");
}
pub mod http {
tonic::include_proto!("xray.proxy.http");
}
pub mod loopback {
tonic::include_proto!("xray.proxy.loopback");
}
pub mod shadowsocks {
tonic::include_proto!("xray.proxy.shadowsocks");
}
pub mod shadowsocks_2022 {
tonic::include_proto!("xray.proxy.shadowsocks_2022");
}
pub mod socks {
tonic::include_proto!("xray.proxy.socks");
}
pub mod trojan {
tonic::include_proto!("xray.proxy.trojan");
}
pub mod vless {
tonic::include_proto!("xray.proxy.vless");
pub mod inbound {
tonic::include_proto!("xray.proxy.vless.inbound");
}
pub mod outbound {
tonic::include_proto!("xray.proxy.vless.outbound");
}
}
pub mod vmess {
tonic::include_proto!("xray.proxy.vmess");
pub mod inbound {
tonic::include_proto!("xray.proxy.vmess.inbound");
}
pub mod outbound {
tonic::include_proto!("xray.proxy.vmess.outbound");
}
}
pub mod wireguard {
tonic::include_proto!("xray.proxy.wireguard");
}
}
pub mod transport {
tonic::include_proto!("xray.transport");
pub mod internet {
tonic::include_proto!("xray.transport.internet");
pub mod domainsocket {
tonic::include_proto!("xray.transport.internet.domainsocket");
}
pub mod grpc {
tonic::include_proto!("xray.transport.internet.grpc.encoding");
}
pub mod http {
tonic::include_proto!("xray.transport.internet.http");
}
pub mod httpupgrade {
tonic::include_proto!("xray.transport.internet.httpupgrade");
}
pub mod kcp {
tonic::include_proto!("xray.transport.internet.kcp");
}
pub mod quic {
tonic::include_proto!("xray.transport.internet.quic");
}
pub mod reality {
tonic::include_proto!("xray.transport.internet.reality");
}
pub mod splithttp {
tonic::include_proto!("xray.transport.internet.splithttp");
}
pub mod tcp {
tonic::include_proto!("xray.transport.internet.tcp");
}
pub mod tls {
tonic::include_proto!("xray.transport.internet.tls");
}
pub mod udp {
tonic::include_proto!("xray.transport.internet.udp");
}
pub mod websocket {
tonic::include_proto!("xray.transport.internet.websocket");
}
pub mod headers {
pub mod dns {
tonic::include_proto!("xray.transport.internet.headers.dns");
}
pub mod http {
tonic::include_proto!("xray.transport.internet.headers.http");
}
pub mod noop {
tonic::include_proto!("xray.transport.internet.headers.noop");
}
pub mod srtp {
tonic::include_proto!("xray.transport.internet.headers.srtp");
}
pub mod tls {
tonic::include_proto!("xray.transport.internet.headers.tls");
}
pub mod utp {
tonic::include_proto!("xray.transport.internet.headers.utp");
}
pub mod wechat {
tonic::include_proto!("xray.transport.internet.headers.wechat");
}
pub mod wireguard {
tonic::include_proto!("xray.transport.internet.headers.wireguard");
}
}
}
}
#[cfg(feature = "connect")]
pub async fn connect<S: AsRef<str>>(path: S) -> Result<Channel, Error> {
use tonic::transport::Endpoint;
let path = path.as_ref();
let channel = Endpoint::try_from(format!("https://{path}"))?
.connect()
.await?;
Ok(channel)
}
#[cfg(feature = "client")]
pub struct Client {
channel: Channel,
}
#[cfg(feature = "client")]
impl Client {
#[cfg(feature = "connect")]
pub async fn from_url<S: AsRef<str>>(url: S) -> Result<Self, Error> {
let channel = connect(url).await?;
Ok(Self { channel })
}
#[inline]
pub fn logger(&self) -> LoggerServiceClient<Channel> {
LoggerServiceClient::new(self.channel.clone())
}
#[inline]
pub fn handler(&self) -> HandlerServiceClient<Channel> {
HandlerServiceClient::new(self.channel.clone())
}
#[inline]
pub fn routing(&self) -> RoutingServiceClient<Channel> {
RoutingServiceClient::new(self.channel.clone())
}
#[inline]
pub fn stats(&self) -> StatsServiceClient<Channel> {
StatsServiceClient::new(self.channel.clone())
}
#[inline]
pub fn observatory(&self) -> ObservatoryServiceClient<Channel> {
ObservatoryServiceClient::new(self.channel.clone())
}
#[inline]
pub fn grpc(&self) -> GrpcServiceClient<Channel> {
GrpcServiceClient::new(self.channel.clone())
}
}
#[cfg(test)]
mod tests {
use prost_types::Any;
use crate::app::proxyman::InboundConfig;
#[test]
fn any_roundtrip() {
let original = InboundConfig {};
let any = Any::from_msg(&original).expect("should not fail to encode");
let decoded: InboundConfig = any.to_msg().expect("should not fail to decode");
assert_eq!(original, decoded)
}
}