Skip to content

Commit a9a272c

Browse files
committed
fix: fix vmess protocol convert logic
1 parent dffbf25 commit a9a272c

File tree

15 files changed

+54
-32
lines changed

15 files changed

+54
-32
lines changed

src/protocols/clash/template_processor.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,16 @@ impl ProtocolProcessor for ClashProcessor {
120120
}
121121

122122
// Add other parameters
123-
let skip_keys = ["udp", "name", "type", "server", "port", "server_port", "tag", "method"];
123+
let skip_keys = [
124+
"udp",
125+
"name",
126+
"type",
127+
"server",
128+
"port",
129+
"server_port",
130+
"tag",
131+
"method",
132+
];
124133
for (key, value) in &node.parameters {
125134
if !(is_shadowsocks && key == "udp") && !skip_keys.contains(&key.as_str()) {
126135
config.insert(key.clone(), value.clone());
@@ -152,10 +161,15 @@ impl ClashProcessor {
152161
}
153162

154163
// security → cipher
164+
// If sing-box has no security field, it defaults to "auto", so we need to set cipher: auto in Clash
155165
if let Some(security) = params.get("security") {
156166
config.insert("cipher".to_string(), security.clone());
157-
} else if let Some(method) = &node.method {
158-
config.insert("cipher".to_string(), serde_json::Value::String(method.clone()));
167+
} else {
168+
// Default to "auto" if no security is specified (sing-box default)
169+
config.insert(
170+
"cipher".to_string(),
171+
serde_json::Value::String("auto".to_string()),
172+
);
159173
}
160174

161175
// UDP support - Clash needs explicit setting
@@ -164,7 +178,11 @@ impl ClashProcessor {
164178
// TLS handling
165179
if let Some(tls) = params.get("tls") {
166180
if let Some(tls_obj) = tls.as_object() {
167-
if tls_obj.get("enabled").and_then(|v| v.as_bool()).unwrap_or(false) {
181+
if tls_obj
182+
.get("enabled")
183+
.and_then(|v| v.as_bool())
184+
.unwrap_or(false)
185+
{
168186
config.insert("tls".to_string(), serde_json::Value::Bool(true));
169187

170188
// server_name → servername
@@ -204,7 +222,10 @@ impl ClashProcessor {
204222
ws_opts.insert("max-early-data".to_string(), early_data.clone());
205223
}
206224
if let Some(header_name) = transport_obj.get("early_data_header_name") {
207-
ws_opts.insert("early-data-header-name".to_string(), header_name.clone());
225+
ws_opts.insert(
226+
"early-data-header-name".to_string(),
227+
header_name.clone(),
228+
);
208229
}
209230
if !ws_opts.is_empty() {
210231
config.insert(
@@ -216,7 +237,8 @@ impl ClashProcessor {
216237
"grpc" => {
217238
let mut grpc_opts = serde_json::Map::new();
218239
if let Some(service_name) = transport_obj.get("service_name") {
219-
grpc_opts.insert("grpc-service-name".to_string(), service_name.clone());
240+
grpc_opts
241+
.insert("grpc-service-name".to_string(), service_name.clone());
220242
}
221243
if !grpc_opts.is_empty() {
222244
config.insert(
@@ -327,7 +349,8 @@ impl ClashProcessor {
327349
"grpc" => {
328350
let mut grpc_opts = serde_json::Map::new();
329351
if let Some(service_name) = transport_obj.get("service_name") {
330-
grpc_opts.insert("grpc-service-name".to_string(), service_name.clone());
352+
grpc_opts
353+
.insert("grpc-service-name".to_string(), service_name.clone());
331354
}
332355
if !grpc_opts.is_empty() {
333356
config.insert(
@@ -357,7 +380,10 @@ impl ClashProcessor {
357380
))
358381
})?;
359382

360-
if let Some(proxy_groups) = config.get_mut("proxy-groups").and_then(|v| v.as_array_mut()) {
383+
if let Some(proxy_groups) = config
384+
.get_mut("proxy-groups")
385+
.and_then(|v| v.as_array_mut())
386+
{
361387
for group in proxy_groups.iter_mut() {
362388
if let Some(group_obj) = group.as_object_mut() {
363389
if let Some(proxies) = group_obj.get_mut("proxies") {

src/protocols/singbox/outbound/direct.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,4 @@ pub struct Direct {
99

1010
#[serde(flatten)]
1111
pub dial_params: DialParams,
12-
}
13-
14-
#[derive(Serialize, Deserialize, Debug, Clone)]
15-
pub enum ProxyProtocol {
16-
V1 = 1,
17-
V2,
18-
}
12+
}

src/protocols/singbox/outbound/hysteria.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
use serde_with::skip_serializing_none;
77

88
#[skip_serializing_none]
9-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
9+
#[derive(Serialize, Deserialize, Debug, Clone)]
1010
pub struct Hysteria {
1111
pub tag: String,
1212
pub server: String,

src/protocols/singbox/outbound/hysteria2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
99
use serde_with::skip_serializing_none;
1010

1111
#[skip_serializing_none]
12-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
12+
#[derive(Serialize, Deserialize, Debug, Clone)]
1313
pub struct Hysteria2 {
1414
pub tag: String,
1515
pub server: String,

src/protocols/singbox/outbound/selector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
22
use serde_with::skip_serializing_none;
33

44
#[skip_serializing_none]
5-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
5+
#[derive(Serialize, Deserialize, Debug, Clone)]
66
pub struct Selector {
77
pub tag: String,
88
pub outbounds: Vec<String>,

src/protocols/singbox/outbound/shadowsocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use serde::{ Deserialize, Serialize };
77
use serde_with::skip_serializing_none;
88

99
#[skip_serializing_none]
10-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
10+
#[derive(Serialize, Deserialize, Debug, Clone)]
1111
pub struct Shadowsocks {
1212
pub tag: String,
1313
pub server: String,

src/protocols/singbox/outbound/ssh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use serde_with::skip_serializing_none;
44

55
#[skip_serializing_none]
6-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
6+
#[derive(Serialize, Deserialize, Debug, Clone)]
77
pub struct SSH {
88
pub tag: String,
99
pub server: String,

src/protocols/singbox/outbound/tor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use serde_with::skip_serializing_none;
44

55
#[skip_serializing_none]
6-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
6+
#[derive(Serialize, Deserialize, Debug, Clone)]
77
pub struct Tor {
88
pub tag: String,
99
pub executable_path: Option<String>,
@@ -16,7 +16,7 @@ pub struct Tor {
1616
}
1717

1818
#[skip_serializing_none]
19-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
19+
#[derive(Serialize, Deserialize, Debug, Clone)]
2020
pub struct Torrc {
2121
#[serde(rename = "ClientOnly")]
2222
pub client_only: TorClientOnly,

src/protocols/singbox/outbound/trojan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
33
use serde_with::skip_serializing_none;
44

55
#[skip_serializing_none]
6-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
6+
#[derive(Serialize, Deserialize, Debug, Clone)]
77
pub struct Trojan {
88
pub tag: String,
99
pub server: String,

src/protocols/singbox/outbound/tuic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
use serde_with::skip_serializing_none;
77

88
#[skip_serializing_none]
9-
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
9+
#[derive(Serialize, Deserialize, Debug, Clone)]
1010
pub struct TUIC {
1111
pub tag: String,
1212
pub server: String,

0 commit comments

Comments
 (0)