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

+2
View File
@@ -606,6 +606,8 @@ let
];
zapret2StateDir = "${stateDir}/zapret2";
# The running global instance's strategy map, which proxy-ctl names state.tsv's rows by.
zapret2StrategiesFile = "${runtimeDir}/proxy-suite-zapret/strategies.json";
# Not under zapret2/, which the zapret scope's group writes to: root works here by
# fixed names (the group asks for probes in requests/).
zapret2CutoffDir = "${stateDir}/zapret2-cutoff";
+1
View File
@@ -130,6 +130,7 @@ in
# Only the system-wide instance reads the site lists; per-app zapret handles all traffic.
ZAPRET_AUTO_ENABLED = flag (zapretEngine == "zapret2" && zapretGlobalEnabled);
ZAPRET_STATE_DIR = constants.zapret2StateDir;
ZAPRET_STRATEGIES_FILE = constants.zapret2StrategiesFile;
ZAPRET_CUTOFF_ENABLED = flag zapretCutoffEnabled;
ZAPRET_CUTOFF_DIR = constants.zapret2CutoffDir;
OUTBOUND_INVENTORY_FILE = constants.outboundInventoryFile;
+3 -1
View File
@@ -149,7 +149,9 @@ in
wants = [ "network-online.target" ];
conflicts = awgServiceNames;
wantedBy = [ "multi-user.target" ];
preStart = mkPreStart;
preStart = mkPreStart + ''
ln -sfn ${globalRuntime}/strategies.json ${constants.zapret2StrategiesFile}
'';
runtimeDirectory = "proxy-suite-zapret";
stateDirectory = "proxy-suite/zapret2";
execStart = "${runtime.daemonScript}";
+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"
''}