From 2d48f45c78163602b7eb0c52a998ba1a1480d8a7 Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Tue, 19 Dec 2023 07:49:10 +0800 Subject: [PATCH] feat(importer): add target_net to proxy_to_net --- src/config/importer/clash.rs | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/config/importer/clash.rs b/src/config/importer/clash.rs index adf3aeb4..170e0a30 100644 --- a/src/config/importer/clash.rs +++ b/src/config/importer/clash.rs @@ -115,7 +115,9 @@ fn ghost_net() -> Net { } impl Clash { - fn proxy_to_net(&self, p: Proxy) -> Result { + fn proxy_to_net(&self, p: Proxy, target_net: Option) -> Result { + let target_net = target_net.unwrap_or_else(|| "local".to_string()); + let net = match p.proxy_type.as_ref() { "ss" => { #[derive(Debug, Deserialize)] @@ -141,7 +143,8 @@ impl Clash { let obfs_net = Net::new( "obfs", json!({ - obfs_mode: plugin_opts, + "obfs_mode": obfs_mode, + "net": target_net, }), ); @@ -166,6 +169,7 @@ impl Clash { "cipher": params.cipher, "password": params.password, "udp": params.udp.unwrap_or_default(), + "net": target_net, }), ) } @@ -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, }), ) } @@ -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: {}", @@ -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); }