diff --git a/docs/options/zapret.md b/docs/options/zapret.md index 0d6ecf8..a2e77b8 100644 --- a/docs/options/zapret.md +++ b/docs/options/zapret.md @@ -315,7 +315,9 @@ Extra IPs or CIDRs to unblock\. ## services\.proxy-suite\.zapret\.zapret2\.autoHostlist\.enable 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\ **Default:** `true` diff --git a/modules/proxy-suite/options/zapret2.nix b/modules/proxy-suite/options/zapret2.nix index 755845b..2e3acbc 100644 --- a/modules/proxy-suite/options/zapret2.nix +++ b/modules/proxy-suite/options/zapret2.nix @@ -136,7 +136,9 @@ in default = true; description = '' 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. ''; }; diff --git a/modules/proxy-suite/zapret2/direct-sync.nix b/modules/proxy-suite/zapret2/direct-sync.nix index b6b1bc4..24e6094 100644 --- a/modules/proxy-suite/zapret2/direct-sync.nix +++ b/modules/proxy-suite/zapret2/direct-sync.nix @@ -15,9 +15,12 @@ let inherit (import ../derived.nix { inherit lib cfg; }) constants; stateDir = constants.zapret2StateDir; 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" ( fillTemplate ./direct-sync.template.sh { + learned = if learn then "1" else "0"; path = lib.makeBinPath [ pkgs.coreutils pkgs.diffutils @@ -55,11 +58,13 @@ in path = { description = "proxy-suite - watch zapret2's host lists and verdicts"; wantedBy = [ "paths.target" ]; - pathConfig.PathChanged = map (name: "${stateDir}/${name}") [ - "zapret-hosts-user.txt" - "zapret-hosts-auto.txt" - "zapret-hosts-user-exclude.txt" - "verdicts.tsv" - ]; + pathConfig.PathChanged = map (name: "${stateDir}/${name}") ( + [ "zapret-hosts-user.txt" ] + ++ lib.optional learn "zapret-hosts-auto.txt" + ++ [ + "zapret-hosts-user-exclude.txt" + "verdicts.tsv" + ] + ); }; } diff --git a/modules/proxy-suite/zapret2/direct-sync.template.sh b/modules/proxy-suite/zapret2/direct-sync.template.sh index 008c14c..8d32cc9 100644 --- a/modules/proxy-suite/zapret2/direct-sync.template.sh +++ b/modules/proxy-suite/zapret2/direct-sync.template.sh @@ -3,7 +3,8 @@ # 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 # (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 # for ("unfixable": all of a site's TCP, or only its QUIC), and addresses that leave # connections unanswered ("blocked"). @@ -18,6 +19,7 @@ export PATH=@path@ dir=$1 out=$2 cache=${3:-} +learned=@learned@ # 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. @@ -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 \ --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 verdicts <(lists "$dir/verdicts.tsv") \ "$hosts"' diff --git a/nix/checks/zapret2.nix b/nix/checks/zapret2.nix index 339ccfd..b414fe6 100644 --- a/nix/checks/zapret2.nix +++ b/nix/checks/zapret2.nix @@ -53,9 +53,13 @@ let z2kCutoffProbe = zapret2Z2k.config.systemd.services.proxy-suite-zapret2-cutoff.serviceConfig.ExecStart; socksStart = fixture: fixture.config.systemd.services.proxy-suite-socks.serviceConfig.ExecStart; - directSync = builtins.head ( - lib.splitString " " zapret2Global.config.systemd.services.proxy-suite-zapret2-direct.serviceConfig.ExecStart - ); + directSyncOf = + 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; in @@ -523,6 +527,10 @@ in ${directSync} direct-lists out dns-cache test "$(stat -c %i out/direct.json)" = "$inode" 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 test "$(cat empty-out/direct.json)" = '{"version":1,"rules":[]}' test "$(cat empty-out/proxy.json)" = '{"version":1,"rules":[]}'