fix: disabling z2 autolearn behavior

This commit is contained in:
FUFSoB committed 2026-10-25 19:00:36 +05:00
1 parent a60b2a1286
commit 9d81e975ea
5 files changed
+32 -13

No files matched your search

+3 -1
View File
@@ -315,7 +315,9 @@ Extra IPs or CIDRs to unblock\.
## services\.proxy-suite\.zapret\.zapret2\.autoHostlist\.enable ## services\.proxy-suite\.zapret\.zapret2\.autoHostlist\.enable
Learn blocked sites: after ` failThreshold ` failed connections, a site is treated as Learn blocked sites: after ` failThreshold ` failed connections, a site is treated as
blocked\. When off, only ` zapret2.domains ` and ` proxy-ctl zapret auto add ` are used\. blocked\. When off, only ` zapret2.domains ` and ` proxy-ctl zapret auto add ` are used:
the sites already learned are kept but ignored, by zapret2 and ` zapret.directSync `
alike, until it is back on\. Each site’s strategy is still remembered\.
**Type:** boolean\ **Type:** boolean\
**Default:** `true` **Default:** `true`
+3 -1
View File
@@ -136,7 +136,9 @@ in
default = true; default = true;
description = '' description = ''
Learn blocked sites: after `failThreshold` failed connections, a site is treated as Learn blocked sites: after `failThreshold` failed connections, a site is treated as
blocked. When off, only `zapret2.domains` and `proxy-ctl zapret auto add` are used. blocked. When off, only `zapret2.domains` and `proxy-ctl zapret auto add` are used:
the sites already learned are kept but ignored, by zapret2 and `zapret.directSync`
alike, until it is back on. Each site's strategy is still remembered.
''; '';
}; };
+11 -6
View File
@@ -15,9 +15,12 @@ let
inherit (import ../derived.nix { inherit lib cfg; }) constants; inherit (import ../derived.nix { inherit lib cfg; }) constants;
stateDir = constants.zapret2StateDir; stateDir = constants.zapret2StateDir;
outDir = constants.zapret2DirectDir; outDir = constants.zapret2DirectDir;
# Without learning nfqws2 no longer reads the learned list: neither does the sync.
learn = cfg.zapret.zapret2.autoHostlist.enable;
sync = pkgs.writeShellScript "proxy-suite-zapret2" ( sync = pkgs.writeShellScript "proxy-suite-zapret2" (
fillTemplate ./direct-sync.template.sh { fillTemplate ./direct-sync.template.sh {
learned = if learn then "1" else "0";
path = lib.makeBinPath [ path = lib.makeBinPath [
pkgs.coreutils pkgs.coreutils
pkgs.diffutils pkgs.diffutils
@@ -55,11 +58,13 @@ in
path = { path = {
description = "proxy-suite - watch zapret2's host lists and verdicts"; description = "proxy-suite - watch zapret2's host lists and verdicts";
wantedBy = [ "paths.target" ]; wantedBy = [ "paths.target" ];
pathConfig.PathChanged = map (name: "${stateDir}/${name}") [ pathConfig.PathChanged = map (name: "${stateDir}/${name}") (
"zapret-hosts-user.txt" [ "zapret-hosts-user.txt" ]
"zapret-hosts-auto.txt" ++ lib.optional learn "zapret-hosts-auto.txt"
"zapret-hosts-user-exclude.txt" ++ [
"verdicts.tsv" "zapret-hosts-user-exclude.txt"
]; "verdicts.tsv"
]
);
}; };
} }
@@ -3,7 +3,8 @@
# direct.json: the hosts zapret2 handles, so the proxy sends them direct and zapret2 sees # direct.json: the hosts zapret2 handles, so the proxy sends them direct and zapret2 sees
# them: the pinned ones, and the learned ones once a strategy got through for them # them: the pinned ones, and the learned ones once a strategy got through for them
# (detect.lua's "works"), unless learned from transfers cut short ("stalls"); a learned # (detect.lua's "works"), unless learned from transfers cut short ("stalls"); a learned
# site zapret2 cannot fix keeps the proxy's route. # site zapret2 cannot fix keeps the proxy's route. With learning off
# (autoHostlist.enable), the pinned ones alone: nfqws2 no longer reads the learned list.
# proxy.json: what zapret2 cannot fix, for the proxy to carry: sites every strategy failed # proxy.json: what zapret2 cannot fix, for the proxy to carry: sites every strategy failed
# for ("unfixable": all of a site's TCP, or only its QUIC), and addresses that leave # for ("unfixable": all of a site's TCP, or only its QUIC), and addresses that leave
# connections unanswered ("blocked"). # connections unanswered ("blocked").
@@ -18,6 +19,7 @@ export PATH=@path@
dir=$1 dir=$1
out=$2 out=$2
cache=${3:-} cache=${3:-}
learned=@learned@
# The zapret scope's group writes these: never through a symlink it left (to a file only # The zapret scope's group writes these: never through a symlink it left (to a file only
# root may read, which would land in the world-readable rule-sets), nor into a FIFO. # root may read, which would land in the world-readable rule-sets), nor into a FIFO.
@@ -67,7 +69,7 @@ hosts='def octet: "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])";
jq -n -c \ jq -n -c \
--rawfile user <(lists "$dir/zapret-hosts-user.txt") \ --rawfile user <(lists "$dir/zapret-hosts-user.txt") \
--rawfile auto <(lists "$dir/zapret-hosts-auto.txt") \ --rawfile auto <(if [ "$learned" = 1 ]; then lists "$dir/zapret-hosts-auto.txt"; fi) \
--rawfile excluded <(lists "$dir/zapret-hosts-user-exclude.txt") \ --rawfile excluded <(lists "$dir/zapret-hosts-user-exclude.txt") \
--rawfile verdicts <(lists "$dir/verdicts.tsv") \ --rawfile verdicts <(lists "$dir/verdicts.tsv") \
"$hosts"' "$hosts"'
+11 -3
View File
@@ -53,9 +53,13 @@ let
z2kCutoffProbe = z2kCutoffProbe =
zapret2Z2k.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart; zapret2Z2k.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart;
socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart; socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart;
directSync = builtins.head ( directSyncOf =
lib.splitString " " zapret2Global.config.systemd.services.proxy-suite-zapret2-direct.serviceConfig.ExecStart fixture:
); builtins.head (
lib.splitString " " fixture.config.systemd.services.proxy-suite-zapret2-direct.serviceConfig.ExecStart
);
directSync = directSyncOf zapret2Global;
noAutoDirectSync = directSyncOf zapret2NoAuto;
proxyCtlEnv = fixture: (mkProxyCtlDerived fixture).wrapperEnv; proxyCtlEnv = fixture: (mkProxyCtlDerived fixture).wrapperEnv;
in in
@@ -523,6 +527,10 @@ in
${directSync} direct-lists out dns-cache ${directSync} direct-lists out dns-cache
test "$(stat -c %i out/direct.json)" = "$inode" test "$(stat -c %i out/direct.json)" = "$inode"
test "$(cat out/names.tsv)" = "$(printf '149.154.167.99\tother.example,www.example.com')" test "$(cat out/names.tsv)" = "$(printf '149.154.167.99\tother.example,www.example.com')"
# Learning off: nfqws2 ignores what was learned, so the proxy does too.
mkdir no-auto-out
${noAutoDirectSync} direct-lists no-auto-out dns-cache
test "$(cat no-auto-out/direct.json)" = '{"version":1,"rules":[{"domain_suffix":["pinned.example"]}]}'
${directSync} empty-lists empty-out ${directSync} empty-lists empty-out
test "$(cat empty-out/direct.json)" = '{"version":1,"rules":[]}' test "$(cat empty-out/direct.json)" = '{"version":1,"rules":[]}'
test "$(cat empty-out/proxy.json)" = '{"version":1,"rules":[]}' test "$(cat empty-out/proxy.json)" = '{"version":1,"rules":[]}'