feat: zapret2 shows strategies applied

This commit is contained in:
FUFSoB committed 2026-09-30 22:25:40 +05:00
1 parent 730671ea0c
commit 0d13822175
8 files changed
+168 -14

No files matched your search

+61 -8
View File
@@ -220,6 +220,57 @@ let
{ cat ${header}; printf "NFQWS2_OPT='%s'\n" "$opt"; } >"$out"
'';
# {circular key: {strategy: [its desync instances]}}, for proxy-ctl to name the
# strategy state.tsv remembers. A circular without key= is keyed by its instance,
# <func>_<profile>_<nth desync of the profile>, counting profiles from 1 and
# templates apart; a profile that imports a template rotates over its strategies.
mkStrategies =
config:
pkgs.runCommand "proxy-suite-zapret2-strategies.json" { nativeBuildInputs = [ pkgs.gawk ]; } ''
. ${config}
set -f
printf '%s\n' $NFQWS2_OPT | awk '
function js(s) { gsub(/\\/, "\\\\", s); gsub(/"/, "\\\"", s); return "\"" s "\"" }
# Numeric from the start: an unset s indexes the first section as "", not 0.
BEGIN { s = 0 }
$0 == "--new" { s++; next }
/^--template=/ { tpl[substr($0, 12)] = s; istpl[s] = 1; next }
/^--import=/ { imp[s] = substr($0, 10); next }
/^--lua-desync=/ {
fn[s]++
spec = substr($0, 14)
if (spec ~ /^circular(:|$)/) {
circ[s] = fn[s]
if (match(spec, /:key=[^:]+/)) key[s] = substr(spec, RSTART + 5, RLENGTH - 5)
} else if (match(spec, /:strategy=[0-9]+/)) {
n = substr(spec, RSTART + 10, RLENGTH - 10)
spec = substr(spec, 1, RSTART - 1) substr(spec, RSTART + RLENGTH)
if (!((s, n) in strat)) order[s] = order[s] " " n
strat[s, n] = ((s, n) in strat ? strat[s, n] "," : "") js(spec)
}
}
END {
printf "{"
for (i = 0; i <= s; i++) {
if (istpl[i]) continue
p++
if (!(i in circ)) continue
k = (i in key) ? key[i] : "circular_" p "_" circ[i]
src = (i in imp && imp[i] in tpl) ? tpl[imp[i]] : ""
printf "%s%s:{", (out++ ? "," : ""), js(k)
m = 0
for (pass = 0; pass < 2; pass++) {
j = pass ? src : i
if (j == "") continue
c = split(order[j], ns, " ")
for (x = 1; x <= c; x++) printf "%s%s:[%s]", (m++ ? "," : ""), js(ns[x]), strat[j, ns[x]]
}
printf "}"
}
print "}"
}' >"$out"
'';
# Keep desync off TUN interfaces (it breaks proxied handshakes), off per-app
# traffic, and off exempted subnets (e.g. NATed VMs whose traffic it would break).
mkCustomScript =
@@ -291,16 +342,18 @@ let
customScript ? null,
...
}@args:
let
config = mkConfig (
builtins.removeAttrs args [
"name"
"customScript"
]
);
in
pkgs.runCommand name { } ''
mkdir -p "$out/init.d/sysv/custom.d"
cp ${
mkConfig (
builtins.removeAttrs args [
"name"
"customScript"
]
)
} "$out/config"
cp ${config} "$out/config"
cp ${mkStrategies config} "$out/strategies.json"
${lib.optionalString (customScript != null) ''
cp ${customScript} "$out/init.d/sysv/custom.d/50-proxy-suite-custom.sh"
''}