Skip to content

Commit

Permalink
config/json: support VMess outbound
Browse files Browse the repository at this point in the history
  • Loading branch information
eycorsican committed Dec 5, 2023
1 parent fcb0879 commit 9f86ee2
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions leaf/src/config/json/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ pub struct TrojanOutboundSettings {
pub password: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct VMessOutboundSettings {
pub address: Option<String>,
pub port: Option<u16>,
pub uuid: Option<String>,
pub security: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct TryAllOutboundSettings {
pub actors: Option<Vec<String>>,
Expand Down Expand Up @@ -650,6 +658,24 @@ pub fn to_internal(json: &mut Config) -> Result<internal::Config> {
outbound.settings = settings;
outbounds.push(outbound);
}
"vmess" => {
if ext_outbound.settings.is_none() {
return Err(anyhow!("invalid vmess outbound settings"));
}
let mut settings = internal::VMessOutboundSettings::new();
let ext_settings: VMessOutboundSettings =
serde_json::from_str(ext_outbound.settings.as_ref().unwrap().get())
.unwrap();
settings.address = ext_settings.address.unwrap_or_default();
settings.port = ext_settings.port.map(|x| x as u32).unwrap_or_default();
settings.uuid = ext_settings.uuid.unwrap_or_default();
settings.security = ext_settings
.security
.unwrap_or(String::from("chacha20-ietf-poly1305"));
let settings = settings.write_to_bytes().unwrap();
outbound.settings = settings;
outbounds.push(outbound);
}
"tls" => {
let mut settings = internal::TlsOutboundSettings::new();
if ext_outbound.settings.is_some() {
Expand Down

0 comments on commit 9f86ee2

Please sign in to comment.