windows: the XRay-only backend; zapret beside the TUN
XRay alone (proxy.backend = "xray"), as upstream's xray.nix and its start-time filter make it: the mixed-in listener with its login, DNS remote and local ordered by the route mode with the servers' names on local, IPIfNonMatch routing in upstream's order and modes, zapret's direct lists; urltest as prefixed tags under a leastPing balancer and observatory, a pin or first as one exit; chains by dialerProxy; Tor, SSH, WARP, AmneziaWG and whitelist-bypass as SOCKS hops. What needs sing-box is refused for it, as upstream asserts (TUN, groups, rule sets, autoProxy, selector/failover, DoT, dns.strategy and the like). The service checks it with xray run -test and runs it with its component's geodata (XRAY_LOCATION_ASSET); latency tests and autoProxy stand aside. zapret beside the TUN: winws2 gets the TUN's addresses left out in its --wf-raw-filter (with the cutoff probe's ports); Flowseal's winws, which takes no ANDed part, gets its own filter as it saves it (--wf-save) with them left out, through --wf-raw. WinDivert negates single tests only: the part is spelled positively, and compiled by WinDivert's own parser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2dd563ed61
commit
d675fdddb5
15 files changed
+831
-34
No files matched your search
@@ -437,6 +437,9 @@ pub async fn handle(req: Request, peer: &Peer, shared: &Shared) -> Response {
|
||||
}
|
||||
|
||||
Request::Test { tags } => {
|
||||
if shared.lock().await.cfg().proxy.backend == ps_core::config::Backend::Xray {
|
||||
return Response::err("latency tests need the sing-box or hybrid backend");
|
||||
}
|
||||
let (clash, tags, url) = {
|
||||
let s = shared.lock().await;
|
||||
let Some(r) = &s.last else { return Response::err("the proxy is not running") };
|
||||
|
||||
@@ -251,7 +251,8 @@ async fn get_text(port: u16, login: &(String, String), url: &str) -> Option<Stri
|
||||
/// The probe listeners, when autoProxy runs with the local proxy.
|
||||
pub fn exits(s: &crate::service::Service) -> Option<Exits> {
|
||||
let cfg = s.cfg();
|
||||
if !(cfg.enable && cfg.proxy.enable && cfg.proxy.auto_proxy.enable) || s.sup.state_of(SOCKS_UNIT) != UnitState::Active {
|
||||
// No Clash API on the xray backend (validated away too).
|
||||
if !(cfg.enable && cfg.proxy.enable && cfg.proxy.auto_proxy.enable) || cfg.proxy.backend == ps_core::config::Backend::Xray || s.sup.state_of(SOCKS_UNIT) != UnitState::Active {
|
||||
return None;
|
||||
}
|
||||
let list = s.last.as_ref()?.probe_exits.clone();
|
||||
|
||||
@@ -418,14 +418,26 @@ impl Service {
|
||||
// last good one running.
|
||||
let candidate = run.join("candidate.json");
|
||||
write_atomic(&candidate, &main_json)?;
|
||||
if backend != Backend::Xray {
|
||||
let out = tokio::process::Command::new(&main_program).args(["check", "-c"]).arg(&candidate).output().await?;
|
||||
if !out.status.success() {
|
||||
let why = String::from_utf8_lossy(&out.stderr).trim().to_owned();
|
||||
self.last_error = Some(format!("sing-box refused the rendered config: {why}"));
|
||||
self.sup.note(SOCKS_UNIT, format!("proxy-suite: sing-box refused the new config, keeping the old one: {why}"));
|
||||
anyhow::bail!("sing-box refused the rendered config: {why}");
|
||||
// XRay keeps its geodata beside xray.exe (the component's directory).
|
||||
let asset_dir = main_program.parent().map(|d| d.to_string_lossy().into_owned());
|
||||
let out = if backend == Backend::Xray {
|
||||
let mut cmd = tokio::process::Command::new(&main_program);
|
||||
cmd.args(["run", "-test", "-c"]).arg(&candidate);
|
||||
if let Some(dir) = &asset_dir {
|
||||
cmd.env("XRAY_LOCATION_ASSET", dir);
|
||||
}
|
||||
cmd.output().await?
|
||||
} else {
|
||||
tokio::process::Command::new(&main_program).args(["check", "-c"]).arg(&candidate).output().await?
|
||||
};
|
||||
if !out.status.success() {
|
||||
let name = if backend == Backend::Xray { "xray" } else { "sing-box" };
|
||||
// XRay reports on stdout as well.
|
||||
let text = if backend == Backend::Xray { [&out.stdout[..], &out.stderr[..]].concat() } else { out.stderr.clone() };
|
||||
let why = String::from_utf8_lossy(&text).trim().to_owned();
|
||||
self.last_error = Some(format!("{name} refused the rendered config: {why}"));
|
||||
self.sup.note(SOCKS_UNIT, format!("proxy-suite: {name} refused the new config, keeping the old one: {why}"));
|
||||
anyhow::bail!("{name} refused the rendered config: {why}");
|
||||
}
|
||||
if !same_content(&main_path, &main_json) {
|
||||
std::fs::rename(&candidate, &main_path)?;
|
||||
@@ -438,7 +450,7 @@ impl Service {
|
||||
name: SOCKS_UNIT.into(),
|
||||
program: main_program,
|
||||
args,
|
||||
env: Vec::new(),
|
||||
env: if backend == Backend::Xray { asset_dir.map(|d| vec![("XRAY_LOCATION_ASSET".to_owned(), d)]).unwrap_or_default() } else { Vec::new() },
|
||||
cwd: Some(run.clone()),
|
||||
generation: digest(&main_json),
|
||||
});
|
||||
|
||||
@@ -50,6 +50,12 @@ fn with_sep(p: &Path) -> String {
|
||||
/// The unit for zapret-discord-youtube: the preset's winws.exe line, with the lists in the
|
||||
/// service's run directory (the release's own, the user's entries added) and the game
|
||||
/// filter. `program` is the verified winws.exe.
|
||||
/// The TUN's packets, left out of WinDivert's filter, when the proxy has a TUN.
|
||||
fn tun_keep_off(cfg: &Config) -> Option<String> {
|
||||
let p = &cfg.proxy;
|
||||
(p.enable && p.tun.enable).then(|| zapret::tun_exclusion(&p.tun.address, p.ipv6.then_some(ps_core::render::TUN_IPV6_ADDRESS))).flatten()
|
||||
}
|
||||
|
||||
pub fn discord_youtube_unit(cfg: &Config, paths: &Paths, program: PathBuf) -> Result<UnitSpec> {
|
||||
let y = &cfg.zapret.discord_youtube;
|
||||
let component = paths.bin().join("zapret");
|
||||
@@ -113,6 +119,26 @@ pub fn discord_youtube_unit(cfg: &Config, paths: &Paths, program: PathBuf) -> Re
|
||||
if cfg.debug.log_level != ps_core::config::LogLevel::Warn {
|
||||
argv.insert(0, "--debug=1".into());
|
||||
}
|
||||
// Beside the TUN: Flowseal's winws takes no filter part ANDed with the rest, so its whole
|
||||
// filter, as it saves it itself for these arguments, with the TUN's packets left out.
|
||||
let mut filter = String::new();
|
||||
if cfg!(windows)
|
||||
&& let Some(keep_off) = tun_keep_off(cfg)
|
||||
{
|
||||
let saved = paths.run().join("zapret").join("winws-own-filter.txt");
|
||||
let _ = std::fs::remove_file(&saved);
|
||||
let mut cmd = std::process::Command::new(&program);
|
||||
cmd.arg(format!("--wf-save={}", saved.display())).args(&argv).current_dir(&bin_dir);
|
||||
cmd.stdin(std::process::Stdio::null()).stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null());
|
||||
#[cfg(windows)]
|
||||
std::os::windows::process::CommandExt::creation_flags(&mut cmd, 0x0800_0000); // CREATE_NO_WINDOW
|
||||
let _ = cmd.status();
|
||||
let own = std::fs::read_to_string(&saved).context("winws did not save its filter (--wf-save), to leave the TUN out of it")?;
|
||||
filter = format!("({})\nand\n({keep_off})\n", own.trim());
|
||||
let file = paths.run().join("zapret").join("winws-filter.txt");
|
||||
write_atomic(&file, filter.as_bytes())?;
|
||||
argv = zapret::with_raw_filter(&argv, &file.to_string_lossy());
|
||||
}
|
||||
// A change of the arguments or of a list winws reads is a restart.
|
||||
let generation = {
|
||||
use sha2::{Digest, Sha256};
|
||||
@@ -121,6 +147,7 @@ pub fn discord_youtube_unit(cfg: &Config, paths: &Paths, program: PathBuf) -> Re
|
||||
h.update(a.as_bytes());
|
||||
h.update(b"\n");
|
||||
}
|
||||
h.update(filter.as_bytes());
|
||||
for f in ["list-general-user.txt", "list-exclude-user.txt", "ipset-exclude-user.txt", "ipset-all.txt"].iter().map(|f| f.to_string()).chain(rule_files) {
|
||||
h.update(std::fs::read(lists.join(&f)).unwrap_or_default());
|
||||
}
|
||||
@@ -214,6 +241,7 @@ pub fn zapret2_unit(cfg: &Config, paths: &Paths, program: PathBuf) -> Result<Uni
|
||||
exclude: exclude.to_string_lossy().into_owned(),
|
||||
auto: auto.to_string_lossy().into_owned(),
|
||||
extras,
|
||||
keep_off: tun_keep_off(cfg),
|
||||
};
|
||||
let argv = zapret2::args(z, &source, &p, cfg.debug.zapret2.packets).map_err(anyhow::Error::msg)?;
|
||||
// Read inside winws2 by z2k's state layer, the detector and the per-site key.
|
||||
|
||||
Reference in new issue
Block a user