feat: select zapret2 strategies source
This commit is contained in:
14 files changed
+566
-208
No files matched your search
@@ -215,6 +215,7 @@
|
||||
nativeBuildInputs = [
|
||||
pkgs.bash
|
||||
pkgs.coreutils
|
||||
pkgs.gawk
|
||||
pkgs.gnugrep
|
||||
];
|
||||
}
|
||||
@@ -247,8 +248,17 @@
|
||||
# The lists stay readable by unprivileged proxy-ctl after a rewrite.
|
||||
test "$(stat -c %a "$state/zapret-hosts-user.txt")" = 644
|
||||
|
||||
# Forgetting a host also drops the strategy remembered for its apex.
|
||||
mkdir -p "$state/circular"
|
||||
printf '# key\thost\tstrategy\tts\tmode\tsni\nrkn_tcp\tyoutube.com\t3\t1\tauto\t\nrkn_tcp\tother.example\t2\t1\tauto\t\nyt_tcp\tyoutube.com\t5\t1\tauto\t\n' > "$state/circular/state.tsv"
|
||||
run forget www.youtube.com > /dev/null
|
||||
! grep -q 'youtube.com' "$state/circular/state.tsv"
|
||||
grep -q 'other.example' "$state/circular/state.tsv"
|
||||
grep -q '^# key' "$state/circular/state.tsv"
|
||||
|
||||
run clear > /dev/null
|
||||
run list | grep -q 'No hostnames learned'
|
||||
test ! -s "$state/circular/state.tsv"
|
||||
|
||||
# Without the zapret2 engine there is nothing to inspect.
|
||||
! env ZAPRET_AUTO_ENABLED=0 ZAPRET_STATE_DIR="$state" bash "$proxy_ctl" zapret auto list
|
||||
|
||||
+50
-16
@@ -17,6 +17,7 @@ let
|
||||
zapret2PerApp
|
||||
zapret2Tuned
|
||||
zapret2NoAuto
|
||||
zapret2Z2k
|
||||
;
|
||||
|
||||
envValue =
|
||||
@@ -40,6 +41,7 @@ let
|
||||
perAppRuntime = runtimeDir zapret2PerApp perAppService;
|
||||
tunedRuntime = runtimeDir zapret2Tuned globalService;
|
||||
noAutoRuntime = runtimeDir zapret2NoAuto globalService;
|
||||
z2kRuntime = runtimeDir zapret2Z2k globalService;
|
||||
|
||||
proxyCtlEnv = fixture: (mkProxyCtlDerived fixture).wrapperEnv;
|
||||
in
|
||||
@@ -61,6 +63,8 @@ in
|
||||
zapret2Global.config.systemd.services.${globalService}.serviceConfig.StateDirectory
|
||||
== "proxy-suite";
|
||||
assert envValue zapret2PerApp perAppService "HOSTLIST_BASE=" == "/var/lib/proxy-suite/zapret2";
|
||||
assert
|
||||
envValue zapret2PerApp perAppService "Z2K_STATE_DIR_OVERRIDE=" == "/var/lib/proxy-suite/zapret2/circular";
|
||||
true
|
||||
)
|
||||
|
||||
@@ -117,6 +121,25 @@ in
|
||||
grep -qF -- '<HOSTLIST_NOAUTO> --hostlist-domains=pinned.example --hostlist-exclude-domains=excluded.example' "${tunedRuntime}/config"
|
||||
test "$(grep -oF -- '--hostlist-domains=pinned.example' "${tunedRuntime}/config" | wc -l)" = 2
|
||||
|
||||
# --- strategy sources -----------------------------------------------
|
||||
# nfqws2-keenetic by default; every source remembers strategies across restarts.
|
||||
grep -qx 'NFQWS2_PORTS_TCP=80,443,1984,2053,2083,2087,2096,5222,8443' "${globalRuntime}/config"
|
||||
grep -qx 'NFQWS2_PORTS_UDP=443,590-600,1400,3478-3481,5349,19294-19344,49152-65535' "${globalRuntime}/config"
|
||||
grep -qF -- '/files/lua/z2k-state-persist.lua' "${globalRuntime}/config"
|
||||
# autoHostlist fills what circular leaves unset; the source keeps its fails and time.
|
||||
grep -qF -- '--lua-desync=circular:fails=2:time=300:retrans=3:nld=2:maxseq=32768:inseq=4096:udp_out=4:udp_in=1:reset ' "${globalRuntime}/config"
|
||||
|
||||
# z2k: its generator's pools, detectors and fake TTL; only the general profile learns.
|
||||
grep -qx 'NFQWS2_TCP_PKT_OUT=20' "${z2kRuntime}/config"
|
||||
grep -qx 'NFQWS2_UDP_PKT_IN=8' "${z2kRuntime}/config"
|
||||
grep -qx 'NFQWS2_PORTS_UDP=443,50000-50099,1400,3478-3481,5349,19294-19344' "${z2kRuntime}/config"
|
||||
grep -qF -- 'key=rkn_tcp:nld=2:failure_detector=z2k_fail_tls_alert:retrans=3:maxseq=32768:inseq=4096:udp_out=4:udp_in=1:reset' "${z2kRuntime}/config"
|
||||
grep -qF -- 'failure_detector=z2k_fail_quic_silence' "${z2kRuntime}/config"
|
||||
grep -qF -- ':fool=z2k_dynamic_ttl' "${z2kRuntime}/config"
|
||||
grep -qF -- '/extra_strats/TCP_Discord.txt <HOSTLIST> ' "${z2kRuntime}/config"
|
||||
test "$(grep -oF -- '<HOSTLIST>' "${z2kRuntime}/config" | wc -l)" = 1
|
||||
grep -qF -- '/lists/whitelist.txt --hostlist-exclude=/var/lib/proxy-suite/zapret2/zapret-hosts-user-exclude.txt' "${z2kRuntime}/config"
|
||||
|
||||
# --- per-app instance -------------------------------------------------
|
||||
# Wrapped apps opted in explicitly, so no hostlist gates them.
|
||||
grep -qx 'MODE_FILTER=none' "${perAppRuntime}/config"
|
||||
@@ -132,31 +155,42 @@ in
|
||||
grep -q 'nft insert rule inet $ZAPRET_NFT_TABLE prenat mark and 0x10000000 != 0 return' "$hook"
|
||||
|
||||
# --- the command line nfqws2 receives ---
|
||||
# Expand <HOSTLIST> with zapret2's list.sh and let nfqws2 validate the result.
|
||||
# Expand <HOSTLIST> with zapret2's list.sh and let nfqws2 validate the result,
|
||||
# Lua included; the strategy state layer gets a writable directory.
|
||||
export HOSTLIST_BASE="$PWD/lists"
|
||||
export ZAPRET_BASE="$base"
|
||||
mkdir -p "$HOSTLIST_BASE"
|
||||
export Z2K_STATE_DIR_OVERRIDE="$PWD/circular"
|
||||
mkdir -p "$HOSTLIST_BASE" "$Z2K_STATE_DIR_OVERRIDE"
|
||||
touch "$HOSTLIST_BASE/zapret-hosts-auto.txt" \
|
||||
"$HOSTLIST_BASE/zapret-hosts-user.txt" \
|
||||
"$HOSTLIST_BASE/zapret-hosts-user-exclude.txt"
|
||||
|
||||
. "${globalRuntime}/config"
|
||||
. "$base/common/base.sh"
|
||||
. "$base/common/list.sh"
|
||||
dry_run() (
|
||||
. "$1/config"
|
||||
. "$base/common/base.sh"
|
||||
. "$base/common/list.sh"
|
||||
|
||||
opt="--qnum=$QNUM $NFQWS2_OPT"
|
||||
filter_apply_hostlist_target opt
|
||||
opt="--qnum=$QNUM $NFQWS2_OPT"
|
||||
filter_apply_hostlist_target opt
|
||||
# The service creates its state files; here they live in the sandbox.
|
||||
opt=$(printf '%s' "$opt" | sed "s|/var/lib/proxy-suite/zapret2/|$HOSTLIST_BASE/|g")
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' >"$2"
|
||||
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- "--hostlist-auto=$HOSTLIST_BASE/zapret-hosts-auto.txt"
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- '--hostlist-auto-fail-threshold=3'
|
||||
printf '%s\n' "$opt" | tr ' ' '\n' | grep -qx -- '--hostlist-auto-fail-time=300'
|
||||
# --user is deliberately omitted: the sandbox is not root.
|
||||
"$base/nfq2/nfqws2" --dry-run --fwmark="$DESYNC_MARK" \
|
||||
--lua-init=@"$base/lua/zapret-lib.lua" \
|
||||
--lua-init=@"$base/lua/zapret-antidpi.lua" \
|
||||
--lua-init=@"$base/lua/zapret-auto.lua" \
|
||||
$opt
|
||||
)
|
||||
|
||||
# --user is deliberately omitted: the sandbox is not root.
|
||||
"$base/nfq2/nfqws2" --dry-run --fwmark="$DESYNC_MARK" \
|
||||
--lua-init=@"$base/lua/zapret-lib.lua" \
|
||||
--lua-init=@"$base/lua/zapret-antidpi.lua" \
|
||||
--lua-init=@"$base/lua/zapret-auto.lua" \
|
||||
$opt
|
||||
dry_run ${globalRuntime} global.args
|
||||
grep -qx -- "--hostlist-auto=$HOSTLIST_BASE/zapret-hosts-auto.txt" global.args
|
||||
grep -qx -- '--hostlist-auto-fail-threshold=3' global.args
|
||||
grep -qx -- '--hostlist-auto-fail-time=300' global.args
|
||||
|
||||
dry_run ${z2kRuntime} z2k.args
|
||||
test "$(grep -cx -- "--hostlist-auto=$HOSTLIST_BASE/zapret-hosts-auto.txt" z2k.args)" = 1
|
||||
|
||||
touch "$out"
|
||||
'';
|
||||
|
||||
@@ -58,4 +58,9 @@ in
|
||||
enable = true;
|
||||
zapret2.autoHostlist.enable = false;
|
||||
};
|
||||
|
||||
zapret2Z2k = mkZapret2 {
|
||||
enable = true;
|
||||
zapret2.strategySource = "z2k";
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user