mirror of https://github.com/ospab/ostp.git
fix: panic on startup due to clap args conflict; add l4_protocol parsing
This commit is contained in:
parent
cf72198b1f
commit
ad3a8cbe8c
|
|
@ -21,7 +21,7 @@ pub async fn run_tun_inbound(
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use futures::{StreamExt, SinkExt};
|
use futures::{StreamExt, SinkExt};
|
||||||
|
|
||||||
let InboundConfig::Tun { tag, auto_route, mtu, fd, .. } = inbound_config else {
|
let InboundConfig::Tun { tag, auto_route, mtu, fd: _fd, .. } = inbound_config else {
|
||||||
return Err(anyhow!("Invalid config for TUN inbound"));
|
return Err(anyhow!("Invalid config for TUN inbound"));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,10 @@ pub struct TransportConfigRaw {
|
||||||
pub wss: Option<bool>,
|
pub wss: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_l4_protocol_config() -> String {
|
||||||
|
"all".to_string()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||||
#[serde(tag = "protocol", rename_all = "snake_case")]
|
#[serde(tag = "protocol", rename_all = "snake_case")]
|
||||||
pub enum ServerOutbound {
|
pub enum ServerOutbound {
|
||||||
|
|
@ -89,6 +93,8 @@ pub enum ServerOutbound {
|
||||||
tag: String,
|
tag: String,
|
||||||
server: String,
|
server: String,
|
||||||
port: u16,
|
port: u16,
|
||||||
|
#[serde(default = "default_l4_protocol_config")]
|
||||||
|
l4_protocol: String,
|
||||||
},
|
},
|
||||||
Direct {
|
Direct {
|
||||||
tag: String,
|
tag: String,
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ struct Args {
|
||||||
update: bool,
|
update: bool,
|
||||||
|
|
||||||
/// Specify a target version for the update command (e.g., -v 0.2.98)
|
/// Specify a target version for the update command (e.g., -v 0.2.98)
|
||||||
#[arg(short = 'v', long = "version", help_heading = "Common Commands")]
|
#[arg(short = 'v', long = "target-version", help_heading = "Common Commands")]
|
||||||
target_version: Option<String>,
|
target_version: Option<String>,
|
||||||
|
|
||||||
/// Import a share link (ostp://...) into the configuration file and exit
|
/// Import a share link (ostp://...) into the configuration file and exit
|
||||||
|
|
@ -1199,7 +1199,7 @@ async fn run_app() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.update {
|
if args.update {
|
||||||
return cmd_update();
|
return cmd_update(args.target_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
if args.migrate {
|
if args.migrate {
|
||||||
|
|
@ -1860,7 +1860,7 @@ async fn run_app() -> Result<()> {
|
||||||
|
|
||||||
let mut outbound = None;
|
let mut outbound = None;
|
||||||
for ob in server_cfg.outbounds {
|
for ob in server_cfg.outbounds {
|
||||||
if let ostp_server::config::ServerOutbound::Socks { server, port, tag } = ob {
|
if let ostp_server::config::ServerOutbound::Socks { server, port, tag, l4_protocol } = ob {
|
||||||
let mut rules = Vec::new();
|
let mut rules = Vec::new();
|
||||||
let mut default_action = Some("proxy".to_string());
|
let mut default_action = Some("proxy".to_string());
|
||||||
if let Some(routing) = &server_cfg.routing {
|
if let Some(routing) = &server_cfg.routing {
|
||||||
|
|
@ -1881,7 +1881,7 @@ async fn run_app() -> Result<()> {
|
||||||
outbound = Some(ostp_server::OutboundConfig {
|
outbound = Some(ostp_server::OutboundConfig {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
protocol: "socks5".to_string(),
|
protocol: "socks5".to_string(),
|
||||||
l4_protocol: "all".to_string(),
|
l4_protocol,
|
||||||
address: server,
|
address: server,
|
||||||
port,
|
port,
|
||||||
rules,
|
rules,
|
||||||
|
|
@ -1987,12 +1987,20 @@ fn cmd_uninstall() -> Result<()> {
|
||||||
// Update command
|
// Update command
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn cmd_update() -> Result<()> {
|
fn cmd_update(version: Option<String>) -> Result<()> {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
println!("[ostp] Updating OSTP...");
|
println!("[ostp] Updating OSTP...");
|
||||||
|
|
||||||
|
let mut script_args = vec!["-c".to_string()];
|
||||||
|
if let Some(v) = version {
|
||||||
|
script_args.push(format!("bash <(curl -Ls https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.sh) -v {}", v));
|
||||||
|
} else {
|
||||||
|
script_args.push("bash <(curl -Ls https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.sh)".to_string());
|
||||||
|
}
|
||||||
|
|
||||||
let status = Command::new("bash")
|
let status = Command::new("bash")
|
||||||
.args(["-c", "bash <(curl -Ls https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.sh)"])
|
.args(&script_args)
|
||||||
.status()
|
.status()
|
||||||
.map_err(|e| anyhow!("Failed to run update: {e}"))?;
|
.map_err(|e| anyhow!("Failed to run update: {e}"))?;
|
||||||
|
|
||||||
|
|
@ -2003,7 +2011,7 @@ fn cmd_update() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn cmd_update() -> Result<()> {
|
fn cmd_update(_version: Option<String>) -> Result<()> {
|
||||||
anyhow::bail!("The 'update' command is only supported on Linux/Unix systems.");
|
anyhow::bail!("The 'update' command is only supported on Linux/Unix systems.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue