Skip to content

Commit

Permalink
feat(importer): add socks5, http translation
Browse files Browse the repository at this point in the history
  • Loading branch information
spacemeowx2 committed Feb 21, 2024
1 parent 14cd4f0 commit 1e718c7
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/config/importer/clash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ fn with_net(mut net: Net, target_net: Option<Net>) -> Net {

impl Clash {
fn proxy_to_net(&self, p: Proxy, target_net: Option<Net>) -> Result<Net> {
let net = match p.proxy_type.as_ref() {
// TODO: http and socks5 has limited support
let net: Net = match p.proxy_type.as_ref() {
"ss" => {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -193,6 +194,7 @@ impl Clash {
// udp is ignored
// udp: Option<bool>,
sni: Option<String>,
#[serde(rename = "skip-cert-verify")]
skip_cert_verify: Option<bool>,
}
let params: Param = serde_json::from_value(p.opt)?;
Expand All @@ -209,6 +211,40 @@ impl Clash {
target_net,
)
}
"http" => {
#[derive(Debug, Deserialize)]
struct Param {
server: String,
port: u16,
}
let params: Param = serde_json::from_value(p.opt)?;
with_net(
Net::new(
"http",
json!({
"server": format!("{}:{}", params.server, params.port),
}),
),
target_net,
)
}
"socks5" => {
#[derive(Debug, Deserialize)]
struct Param {
server: String,
port: u16,
}
let params: Param = serde_json::from_value(p.opt)?;
with_net(
Net::new(
"socks5",
json!({
"server": format!("{}:{}", params.server, params.port),
}),
),
target_net,
)
}
_ => return Err(anyhow!("Unsupported proxy type: {}", p.proxy_type)),
};
Ok(net)
Expand Down

0 comments on commit 1e718c7

Please sign in to comment.