fix: correctly parse transport config section from json in CLI and GUI

This commit is contained in:
ospab 2026-05-21 02:33:14 +03:00
parent aa3fb70933
commit b87e87a7bd
2 changed files with 32 additions and 10 deletions

View File

@ -159,6 +159,14 @@ struct RawUnifiedConfig {
exclude: Option<RawExcludeSection>,
mux: Option<RawMuxSection>,
turn: Option<RawTurnSection>,
transport: Option<RawTransportSection>,
}
#[derive(Debug, Deserialize)]
struct RawTransportSection {
mode: Option<String>,
stealth_sni: Option<String>,
stealth_port: Option<u16>,
}
#[derive(Debug, Deserialize)]
@ -232,14 +240,16 @@ impl ClientConfig {
bind_addr: socks5,
connect_timeout_ms: 15000,
},
turn: match raw.turn {
Some(t) => TurnConfig {
enabled: t.enabled.unwrap_or(false),
server_addr: t.server_addr.unwrap_or_default(),
username: t.username.unwrap_or_default(),
access_key: t.access_key.unwrap_or_default(),
turn: TurnConfig {
enabled: raw.turn.as_ref().and_then(|t| t.enabled).unwrap_or(false),
server_addr: raw.turn.as_ref().and_then(|t| t.server_addr.clone()).unwrap_or_default(),
username: raw.turn.as_ref().and_then(|t| t.username.clone()).unwrap_or_default(),
access_key: raw.turn.as_ref().and_then(|t| t.access_key.clone()).unwrap_or_default(),
},
None => TurnConfig::default(),
transport: TransportConfig {
mode: raw.transport.as_ref().and_then(|t| t.mode.clone()).unwrap_or_else(|| "udp".to_string()),
stealth_sni: raw.transport.as_ref().and_then(|t| t.stealth_sni.clone()).unwrap_or_else(|| "microsoft.com".to_string()),
stealth_port: raw.transport.as_ref().and_then(|t| t.stealth_port).unwrap_or(443),
},
exclusions: ExclusionConfig {
domains: exclusions.domains.unwrap_or_default(),
@ -250,7 +260,6 @@ impl ClientConfig {
enabled: mux.enabled.unwrap_or(false),
sessions: mux.sessions.unwrap_or(1),
},
transport: TransportConfig::default(),
dns_server: raw.tun.as_ref().and_then(|t| t.dns.clone()),
})

View File

@ -60,6 +60,7 @@ fn parse_ostp_link(link: &str) -> Result<ClientConfig> {
server,
access_key,
mtu: None,
transport: None,
socks5_bind: Some("127.0.0.1:1088".to_string()), // Fallback to standard SOCKS5 port
tun: Some(TunConfig {
enable: false, // Default to proxy, configurable via settings GUI
@ -196,6 +197,14 @@ struct ClientConfig {
debug: Option<bool>,
exclude: Option<ExcludeConfig>,
mux: Option<MuxConfig>,
transport: Option<TransportConfigRaw>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
struct TransportConfigRaw {
mode: Option<String>,
stealth_sni: Option<String>,
stealth_port: Option<u16>,
}
#[derive(Debug, Deserialize, Serialize, Clone)]
@ -657,7 +666,11 @@ async fn run_client_directly(client_cfg: ClientConfig) -> Result<()> {
enabled: client_cfg.mux.as_ref().and_then(|m| m.enabled).unwrap_or(false),
sessions: client_cfg.mux.as_ref().and_then(|m| m.sessions).unwrap_or(1),
},
transport: ostp_client::config::TransportConfig::default(),
transport: ostp_client::config::TransportConfig {
mode: client_cfg.transport.as_ref().and_then(|t| t.mode.clone()).unwrap_or_else(|| "udp".to_string()),
stealth_sni: client_cfg.transport.as_ref().and_then(|t| t.stealth_sni.clone()).unwrap_or_else(|| "microsoft.com".to_string()),
stealth_port: client_cfg.transport.as_ref().and_then(|t| t.stealth_port).unwrap_or(443),
},
dns_server: client_cfg.tun.as_ref().and_then(|t| t.dns.clone()),
};