Skip to content

Commit

Permalink
feat(importer): add target_net to proxy_to_net
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Dec 18, 2023
1 parent 707c93b commit 2d48f45
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/config/importer/clash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ fn ghost_net() -> Net {
}

impl Clash {
fn proxy_to_net(&self, p: Proxy) -> Result<Net> {
fn proxy_to_net(&self, p: Proxy, target_net: Option<String>) -> Result<Net> {
let target_net = target_net.unwrap_or_else(|| "local".to_string());

let net = match p.proxy_type.as_ref() {
"ss" => {
#[derive(Debug, Deserialize)]
Expand All @@ -141,7 +143,8 @@ impl Clash {
let obfs_net = Net::new(
"obfs",
json!({
obfs_mode: plugin_opts,
"obfs_mode": obfs_mode,
"net": target_net,
}),
);

Expand All @@ -166,6 +169,7 @@ impl Clash {
"cipher": params.cipher,
"password": params.password,
"udp": params.udp.unwrap_or_default(),
"net": target_net,
}),
)
}
Expand All @@ -190,6 +194,7 @@ impl Clash {
"password": params.password,
"sni": params.sni.unwrap_or(params.server),
"skip_cert_verify": params.skip_cert_verify.unwrap_or_default(),
"net": target_net,
}),
)
}
Expand Down Expand Up @@ -243,6 +248,30 @@ impl Clash {
}),
)
}
"relay" => {
let first_net = net_list
.get(0)
.cloned()
.unwrap_or_else(|| "noop".to_string());
let mut cur = Net::new(
"alias",
json!({
"net": first_net,
}),
);

for net in net_list.into_iter().skip(1) {
cur = Net::new(
"relay",
json!({
"net": net,
"upstream": cur,
}),
);
}

todo!()
}
_ => {
return Err(anyhow!(
"Unsupported proxy group type: {}",
Expand Down Expand Up @@ -390,7 +419,7 @@ impl Importer for Clash {
let name = self.prefix(&old_name);
added_proxies.push(name.clone());
self.name_map.insert(old_name.clone(), name.clone());
match self.proxy_to_net(p) {
match self.proxy_to_net(p, None) {
Ok(p) => {
config.net.insert(name, p);
}
Expand Down

0 comments on commit 2d48f45

Please sign in to comment.