Files
v2ray-proxy/src/parser/vless/mod.rs

119 lines
4.4 KiB
Rust
Raw Normal View History

2025-07-26 16:49:47 +03:30
pub mod data;
2023-10-17 17:27:24 +03:30
mod models;
2025-07-26 16:49:47 +03:30
use crate::{config_models::*, utils::parse_raw_json};
2023-10-20 17:14:56 +03:30
pub fn create_outbound_object(data: models::VlessData) -> Outbound {
let network_type = data.query.r#type.clone().unwrap_or(String::from(""));
2023-10-14 11:30:03 +03:30
return Outbound {
protocol: String::from("vless"),
tag: String::from("proxy"),
2023-10-19 10:04:12 +03:30
streamSettings: StreamSettings {
2023-10-19 11:53:28 +03:30
network: data.query.r#type.clone(),
2023-10-19 10:04:12 +03:30
security: data.query.security.clone(),
tlsSettings: if network_type == String::from("tls") {
2023-10-19 10:04:12 +03:30
Some(TlsSettings {
alpn: data.query.alpn.map(|alpn| vec![alpn]),
2023-10-19 10:04:12 +03:30
rejectUnknownSni: None,
enableSessionResumption: None,
minVersion: None,
maxVersion: None,
cipherSuites: None,
disableSystemRoot: None,
preferServerCipherSuites: None,
fingerprint: data.query.fp.clone(),
serverName: data.query.sni.clone(),
2023-10-19 10:04:12 +03:30
allowInsecure: Some(false),
})
} else {
None
},
wsSettings: if network_type == String::from("ws") {
2023-10-19 11:53:28 +03:30
Some(WsSettings {
2025-07-26 16:32:53 +03:30
Host: data.query.host.clone(),
path: data.query.path.clone(),
2023-10-19 11:53:28 +03:30
acceptProxyProtocol: None,
})
} else {
None
},
tcpSettings: if network_type == String::from("tcp") {
2023-10-19 11:57:44 +03:30
Some(TCPSettings {
2025-07-23 21:00:07 +03:30
header: Some(TCPHeader {
r#type: Some(data.query.header_type.unwrap_or(String::from("none"))),
2023-10-19 11:57:44 +03:30
}),
acceptProxyProtocol: None,
})
} else {
None
},
realitySettings: if network_type == String::from("reality") {
2023-10-19 15:26:41 +03:30
Some(RealitySettings {
publicKey: data.query.pbk,
serverName: data.query.sni.clone(),
shortId: data.query.sid,
spiderX: Some(String::from("")),
fingerprint: data.query.fp.clone(),
2023-10-19 15:26:41 +03:30
})
} else {
None
},
grpcSettings: if network_type == String::from("grpc") {
2023-10-21 11:42:12 +03:30
Some(GRPCSettings {
authority: data.query.authority,
multiMode: Some(false),
2023-10-21 11:42:12 +03:30
serviceName: data.query.service_name,
})
} else {
None
},
quicSettings: if network_type == String::from("quic") {
2023-10-23 19:13:16 +03:30
Some(QuicSettings {
header: Some(NonHeaderObject {
r#type: Some(String::from("none")),
2023-10-23 19:13:16 +03:30
}),
security: Some(String::from("none")),
key: Some(String::from("")),
2023-10-23 19:13:16 +03:30
})
} else {
None
},
2025-07-26 16:08:27 +03:30
kcpSettings: if network_type == String::from("kcp") {
Some(KCPSettings {
mtu: None,
tti: None,
congestion: None,
uplinkCapacity: None,
readBufferSize: None,
writeBufferSize: None,
downlinkCapacity: None,
seed: data.query.seed,
})
} else {
None
},
2025-07-26 16:32:53 +03:30
xhttpSettings: if network_type == String::from("xhttp") {
Some(XHTTPSettings {
host: data.query.host.clone(),
path: data.query.path.clone(),
mode: data.query.mode,
extra: data.query.extra.and_then(|e| parse_raw_json(e.as_str())),
})
} else {
None
},
2023-10-19 10:04:12 +03:30
},
2023-10-14 11:30:03 +03:30
settings: OutboundSettings::Vless(VlessOutboundSettings {
vnext: vec![VlessServerObject {
port: data.address_data.port,
address: data.address_data.address,
users: vec![VlessUser {
id: data.address_data.uuid,
flow: data.query.flow,
encryption: data.query.encryption.unwrap_or(String::from("none")),
level: Some(0),
}],
}],
2023-10-14 11:30:03 +03:30
}),
};
}