Skip to content

Commit 222b161

Browse files
committed
Fix TCP stream setting
1 parent 7398ca5 commit 222b161

File tree

2 files changed

+35
-18
lines changed

2 files changed

+35
-18
lines changed

src/config/xray.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ use crate::memory::tag::ProtoTag as Tag;
88

99
use crate::Result;
1010

11+
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
12+
#[serde(rename_all = "lowercase")]
13+
pub enum Network {
14+
Xhttp,
15+
Grpc,
16+
Tcp,
17+
Ws,
18+
}
19+
1120
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
1221
pub struct StreamSettings {
22+
pub network: Network,
1323
#[serde(rename = "tcpSettings")]
1424
pub tcp_settings: Option<TcpSettings>,
1525
#[serde(rename = "realitySettings")]

src/xray_op/clash.rs

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
use crate::http::requests::InboundResponse;
2-
use crate::Tag;
1+
use crate::config::xray::StreamSettings;
32
use serde::Serialize;
43
use std::net::Ipv4Addr;
54
use uuid::Uuid;
65

6+
use crate::config::xray::Network;
7+
use crate::http::requests::InboundResponse;
8+
use crate::Tag;
9+
710
#[derive(Serialize)]
811
pub struct ClashConfig {
912
port: u16,
@@ -144,19 +147,26 @@ pub fn generate_proxy_config(
144147
Tag::VlessGrpcReality | Tag::VlessTcpReality | Tag::VlessXhttpReality => {
145148
let reality = stream.reality_settings.as_ref()?;
146149

147-
let (network, grpc_opts, flow, http_opts) = if let Some(grpc) = &stream.grpc_settings {
148-
(
150+
// Определяем network, grpc_opts, flow и http_opts
151+
let (network, grpc_opts, flow, http_opts) = match stream {
152+
StreamSettings {
153+
grpc_settings: Some(grpc),
154+
..
155+
} => (
149156
"grpc".to_string(),
150157
Some(GrpcOpts {
151158
grpc_service_name: grpc.service_name.clone(),
152159
ip_version: "dual",
153160
}),
154161
None,
155162
None,
156-
)
157-
} else if let Some(xhttp) = &stream.xhttp_settings {
158-
(
159-
"http".to_string(),
163+
),
164+
StreamSettings {
165+
xhttp_settings: Some(xhttp),
166+
reality_settings: Some(reality),
167+
..
168+
} => (
169+
"http".to_string(), // для Clash Verge / XHTTP Reality используем http
160170
None,
161171
None,
162172
Some(XHttpOpts {
@@ -165,16 +175,17 @@ pub fn generate_proxy_config(
165175
ip_version: "dual",
166176
host: reality.server_names.get(0).cloned().unwrap_or_default(),
167177
}),
168-
)
169-
} else if stream.tcp_settings.is_some() {
170-
(
178+
),
179+
StreamSettings {
180+
network: Network::Tcp,
181+
..
182+
} => (
171183
"tcp".to_string(),
172184
None,
173185
Some("xtls-rprx-vision".to_string()),
174186
None,
175-
)
176-
} else {
177-
return None;
187+
),
188+
_ => return None,
178189
};
179190

180191
let name = format!("{} [{}]", label, inbound.tag);
@@ -185,18 +196,14 @@ pub fn generate_proxy_config(
185196
port,
186197
uuid: conn_id.to_string(),
187198
udp: true,
188-
189199
tls: true,
190200
network,
191201
servername: reality.server_names.get(0).cloned().unwrap_or_default(),
192-
193202
client_fingerprint: "chrome".to_string(),
194-
195203
reality_opts: RealityOpts {
196204
public_key: reality.public_key.clone(),
197205
short_id: reality.short_ids.get(0).cloned().unwrap_or_default(),
198206
},
199-
200207
grpc_opts,
201208
http_opts,
202209
flow,

0 commit comments

Comments
 (0)