fix: zapret2 & naming fixes
This commit is contained in:
32 files changed
+580
-261
No files matched your search
@@ -186,7 +186,7 @@ let
|
||||
# do not race it.
|
||||
after = [
|
||||
"network-online.target"
|
||||
"zapret-discord-youtube.service"
|
||||
"proxy-suite-zapret.service"
|
||||
]
|
||||
++ lib.optional cfg.proxy.enable "proxy-suite-socks.service";
|
||||
wants = [ "network-online.target" ] ++ lib.optional cfg.proxy.enable "proxy-suite-socks.service";
|
||||
@@ -194,7 +194,7 @@ let
|
||||
conflicts = allProfileConflicts name ++ [
|
||||
"proxy-suite-tun.service"
|
||||
"proxy-suite-tproxy.service"
|
||||
"zapret-discord-youtube.service"
|
||||
"proxy-suite-zapret.service"
|
||||
"proxy-suite-per-app-zapret.service"
|
||||
"proxy-suite-zapret-vm-exempt.service"
|
||||
];
|
||||
|
||||
@@ -28,9 +28,9 @@ let
|
||||
lib.types.submodule (
|
||||
{ name, ... }:
|
||||
{
|
||||
config.serviceConfig.SyslogIdentifier = lib.mkIf (
|
||||
lib.hasPrefix "proxy-suite-" name || name == "zapret-discord-youtube"
|
||||
) (lib.mkDefault (lib.removeSuffix "@" name));
|
||||
config.serviceConfig.SyslogIdentifier = lib.mkIf (lib.hasPrefix "proxy-suite-" name) (
|
||||
lib.mkDefault (lib.removeSuffix "@" name)
|
||||
);
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@@ -166,7 +166,7 @@ let
|
||||
# Runtime outbound control. The spool dirs hold one proxy URL per file and are
|
||||
# group-writable when userControl is on, so proxy-ctl edits them without sudo;
|
||||
# the pin outlives a reboot, unlike the per-boot route-mode override.
|
||||
priorityOutboundFile = "/var/lib/proxy-suite/priority-outbound";
|
||||
pinnedOutboundFile = "/var/lib/proxy-suite/pinned-outbound";
|
||||
runtimeOutboundsDir = "/var/lib/proxy-suite/outbounds.d";
|
||||
runtimeSubscriptionsDir = "/var/lib/proxy-suite/subscriptions.d";
|
||||
# Written by every backend start script; proxy-ctl reads the socks copy.
|
||||
|
||||
@@ -61,7 +61,7 @@ in
|
||||
- "selector": all of them, pick by hand.
|
||||
- "urltest": all of them, ranked by latency unless one is pinned.
|
||||
|
||||
`proxy-ctl proxy select` pins an outbound in every mode, and the pin outlives a restart.
|
||||
`proxy-ctl proxy pin` pins an outbound in every mode, and the pin outlives a restart.
|
||||
"selector" and "urltest" switch without restarting the backend (sing-box only); "first"
|
||||
and XRay restart it.
|
||||
'';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
proxyCfg,
|
||||
clashApi,
|
||||
routeModeStateFile,
|
||||
priorityOutboundFile,
|
||||
pinnedOutboundFile,
|
||||
outboundInventoryFile,
|
||||
subscriptionCacheDir,
|
||||
subscriptionCacheHelpersBlock,
|
||||
@@ -77,20 +77,15 @@ let
|
||||
${restartActiveConfigConsumersBlock}
|
||||
'';
|
||||
|
||||
# Pins the outbound the proxy prefers, or "auto" to hand the choice back to the
|
||||
# configured selection. The pin is persisted either way; a live Clash API switch
|
||||
# only saves the restart.
|
||||
setPriorityOutboundScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
# Pins the outbound the proxy prefers; without a tag, unpins it and hands the choice
|
||||
# back to the configured selection. The pin is persisted either way; a live Clash
|
||||
# API switch only saves the restart.
|
||||
pinOutboundScript = pkgs.writeShellScript "proxy-suite-core" ''
|
||||
set -euo pipefail
|
||||
tag="''${1:-}"
|
||||
|
||||
if [ -z "$tag" ]; then
|
||||
echo "proxy-suite: usage: proxy-suite-set-priority-outbound <tag|auto>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$tag" = "auto" ]; then
|
||||
rm -f "${priorityOutboundFile}"
|
||||
rm -f "${pinnedOutboundFile}"
|
||||
else
|
||||
# The inventory only exists once the proxy has run. Without it there is
|
||||
# nothing to check against, so accept the tag and let the start script warn
|
||||
@@ -100,8 +95,8 @@ let
|
||||
echo "proxy-suite: unknown outbound '$tag'" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir -p "$(dirname "${priorityOutboundFile}")"
|
||||
printf '%s\n' "$tag" > "${priorityOutboundFile}"
|
||||
mkdir -p "$(dirname "${pinnedOutboundFile}")"
|
||||
printf '%s\n' "$tag" > "${pinnedOutboundFile}"
|
||||
# Live switch when the running config exposes a selector; the persisted pin
|
||||
# is what keeps it after the next restart.
|
||||
if ${curl} -sf -X PUT "${clashApi}/proxies/proxy" \
|
||||
@@ -146,7 +141,7 @@ in
|
||||
inherit
|
||||
subscriptionUpdateScript
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
;
|
||||
}
|
||||
@@ -46,7 +46,6 @@
|
||||
zapretAutoEnabled = if zapretEngine == "zapret2" then "1" else "0";
|
||||
zapretStateDir = constants.zapret2StateDir;
|
||||
zapretCutoffEnabled = if zapretCutoffEnabled then "1" else "0";
|
||||
priorityOutboundFile = constants.priorityOutboundFile;
|
||||
outboundInventoryFile = constants.outboundInventoryFile;
|
||||
runtimeOutboundsDir = constants.runtimeOutboundsDir;
|
||||
runtimeSubscriptionsDir = constants.runtimeSubscriptionsDir;
|
||||
|
||||
@@ -15,9 +15,8 @@ let
|
||||
}
|
||||
''
|
||||
+ lib.optionalString (builtins.elem "global" userControlCfg.allow) ''
|
||||
if ((unit.indexOf("proxy-suite-") === 0 &&
|
||||
unit.indexOf("proxy-suite-per-app-") !== 0) ||
|
||||
unit === "zapret-discord-youtube.service") {
|
||||
if (unit.indexOf("proxy-suite-") === 0 &&
|
||||
unit.indexOf("proxy-suite-per-app-") !== 0) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
'';
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
backend,
|
||||
backendArg,
|
||||
xraySidecarRoutingMark,
|
||||
priorityOutboundFile,
|
||||
pinnedOutboundFile,
|
||||
runtimeOutboundsDir,
|
||||
jq,
|
||||
python3,
|
||||
@@ -373,14 +373,14 @@ let
|
||||
# entry that went away, say - is dropped rather than left to break the config.
|
||||
pinBlock = ''
|
||||
OUTBOUND_TAGS_JSON=$(${jq} -c '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
PRIORITY_OUTBOUND=""
|
||||
if [ -r "${priorityOutboundFile}" ]; then
|
||||
PRIORITY_OUTBOUND="$(tr -d '\r\n[:space:]' < "${priorityOutboundFile}" 2>/dev/null || true)"
|
||||
PINNED_OUTBOUND=""
|
||||
if [ -r "${pinnedOutboundFile}" ]; then
|
||||
PINNED_OUTBOUND="$(tr -d '\r\n[:space:]' < "${pinnedOutboundFile}" 2>/dev/null || true)"
|
||||
fi
|
||||
if [ -n "$PRIORITY_OUTBOUND" ] \
|
||||
&& ! ${jq} -e --arg t "$PRIORITY_OUTBOUND" 'index($t) != null' <<< "$OUTBOUND_TAGS_JSON" >/dev/null; then
|
||||
echo "proxy-suite: warning: pinned outbound '$PRIORITY_OUTBOUND' is not available; picking automatically" >&2
|
||||
PRIORITY_OUTBOUND=""
|
||||
if [ -n "$PINNED_OUTBOUND" ] \
|
||||
&& ! ${jq} -e --arg t "$PINNED_OUTBOUND" 'index($t) != null' <<< "$OUTBOUND_TAGS_JSON" >/dev/null; then
|
||||
echo "proxy-suite: warning: pinned outbound '$PINNED_OUTBOUND' is not available; picking automatically" >&2
|
||||
PINNED_OUTBOUND=""
|
||||
fi
|
||||
'';
|
||||
|
||||
@@ -389,7 +389,7 @@ let
|
||||
${jq} -n \
|
||||
--argjson tags "$OUTBOUND_TAGS_JSON" \
|
||||
--argjson sources "$OUTBOUND_SOURCES_JSON" \
|
||||
--arg pinned "$PRIORITY_OUTBOUND" \
|
||||
--arg pinned "$PINNED_OUTBOUND" \
|
||||
--arg selection ${lib.escapeShellArg selectionMode} \
|
||||
'{tags: $tags, sources: $sources, pinned: $pinned, selection: $selection}' \
|
||||
> "$RUNTIME_DIR/outbounds.json"
|
||||
@@ -416,15 +416,15 @@ let
|
||||
OUTBOUNDS_JSON=$(${jq} 'map(.tag = ("proxy-suite-ob-" + .tag))' <<< "$OUTBOUNDS_JSON")
|
||||
# XRay has no selector: a pin degrades the balancer to the one outbound,
|
||||
# which is the same path a single-outbound config already takes.
|
||||
if [ -n "$PRIORITY_OUTBOUND" ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="proxy-suite-ob-$PRIORITY_OUTBOUND"
|
||||
if [ -n "$PINNED_OUTBOUND" ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="proxy-suite-ob-$PINNED_OUTBOUND"
|
||||
elif [ "$(${jq} 'length' <<< "$OUTBOUNDS_JSON")" -eq 1 ]; then
|
||||
XRAY_SINGLE_PROXY_TAG="$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")"
|
||||
fi
|
||||
''
|
||||
else if collapseNamedOutbounds then
|
||||
''
|
||||
PROXY_TAG="$PRIORITY_OUTBOUND"
|
||||
PROXY_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$PROXY_TAG" ]; then
|
||||
PROXY_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
fi
|
||||
@@ -434,7 +434,7 @@ let
|
||||
else if selectionMode == "selector" then
|
||||
''
|
||||
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
DEFAULT_TAG="$PRIORITY_OUTBOUND"
|
||||
DEFAULT_TAG="$PINNED_OUTBOUND"
|
||||
if [ -z "$DEFAULT_TAG" ]; then
|
||||
DEFAULT_TAG=$(${jq} -r '.[0].tag' <<< "$OUTBOUNDS_JSON")
|
||||
fi
|
||||
@@ -447,12 +447,12 @@ let
|
||||
else
|
||||
''
|
||||
TAGS=$(${jq} '[.[].tag]' <<< "$OUTBOUNDS_JSON")
|
||||
if [ -n "$PRIORITY_OUTBOUND" ]; then
|
||||
if [ -n "$PINNED_OUTBOUND" ]; then
|
||||
# A pin beats latency ranking: the same outbounds, behind a selector
|
||||
# the Clash API can also switch live.
|
||||
WRAPPER=$(${jq} -n \
|
||||
--argjson tags "$TAGS" \
|
||||
--arg default "$PRIORITY_OUTBOUND" \
|
||||
--arg default "$PINNED_OUTBOUND" \
|
||||
'{type:"selector",tag:"proxy",outbounds:$tags,default:$default}')
|
||||
else
|
||||
WRAPPER=$(${jq} -n \
|
||||
|
||||
@@ -57,7 +57,7 @@ let
|
||||
null;
|
||||
routeModeStateFile = "/run/proxy-suite/route-mode";
|
||||
inherit (constants)
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
@@ -118,7 +118,7 @@ let
|
||||
backend
|
||||
backendArg
|
||||
xraySidecarRoutingMark
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
jq
|
||||
python3
|
||||
@@ -220,7 +220,7 @@ let
|
||||
proxyCfg
|
||||
clashApi
|
||||
routeModeStateFile
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
outboundInventoryFile
|
||||
subscriptionCacheDir
|
||||
subscriptionCacheHelpersBlock
|
||||
@@ -232,7 +232,7 @@ let
|
||||
inherit (controlScripts)
|
||||
subscriptionUpdateScript
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
;
|
||||
|
||||
@@ -250,13 +250,13 @@ in
|
||||
proxyInboundsSubscriptionsFile
|
||||
routeModeStateFile
|
||||
setRouteModeScript
|
||||
setPriorityOutboundScript
|
||||
pinOutboundScript
|
||||
reloadOutboundsScript
|
||||
subscriptionUpdateScript
|
||||
subscriptionTagsFile
|
||||
subscriptionCacheDir
|
||||
runtimeProxychainsConfig
|
||||
priorityOutboundFile
|
||||
pinnedOutboundFile
|
||||
runtimeOutboundsDir
|
||||
runtimeSubscriptionsDir
|
||||
outboundInventoryFile
|
||||
|
||||
@@ -242,10 +242,20 @@ let
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-outbound-select@";
|
||||
name = "proxy-suite-outbound-pin@";
|
||||
value = mkOneshotService {
|
||||
description = "Pin the proxy-suite priority outbound to %i";
|
||||
execStart = "${scripts.setPriorityOutboundScript} %i";
|
||||
description = "Pin the proxy-suite outbound to %i";
|
||||
execStart = "${scripts.pinOutboundScript} %i";
|
||||
stateDirectory = "proxy-suite";
|
||||
extraServiceConfig.RemainAfterExit = false;
|
||||
};
|
||||
}
|
||||
{
|
||||
enable = proxyEnabled;
|
||||
name = "proxy-suite-outbound-unpin";
|
||||
value = mkOneshotService {
|
||||
description = "Unpin the proxy-suite outbound";
|
||||
execStart = "${scripts.pinOutboundScript}";
|
||||
stateDirectory = "proxy-suite";
|
||||
extraServiceConfig.RemainAfterExit = false;
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ in
|
||||
++ lib.optionals perAppZapretCfg.enable [ perAppZapretPackage ]
|
||||
);
|
||||
|
||||
systemd.services.zapret-discord-youtube = lib.mkIf zapretCfg.enable (mkOneshotService {
|
||||
systemd.services.proxy-suite-zapret = lib.mkIf zapretCfg.enable (mkOneshotService {
|
||||
description = "zapret DPI bypass";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
@@ -121,8 +121,8 @@ in
|
||||
lib.mkIf (zapretCfg.enable && zapretCfg.cidrExemption.enable)
|
||||
(mkOneshotService {
|
||||
description = "Exempt CIDRs from zapret NFQUEUE";
|
||||
after = [ "zapret-discord-youtube.service" ];
|
||||
wants = [ "zapret-discord-youtube.service" ];
|
||||
after = [ "proxy-suite-zapret.service" ];
|
||||
wants = [ "proxy-suite-zapret.service" ];
|
||||
conflicts = awgServiceNames;
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
execStart = pkgs.writeShellScript "proxy-suite-zapret" exemptStart;
|
||||
|
||||
@@ -104,7 +104,7 @@ in
|
||||
systemd.services.proxy-suite-zapret2-cutoff = lib.mkIf cutoffCfg.enable cutoff.service;
|
||||
systemd.timers.proxy-suite-zapret2-cutoff = lib.mkIf cutoffCfg.enable cutoff.timer;
|
||||
|
||||
systemd.services.zapret-discord-youtube = lib.mkIf zapretCfg.enable (mkOneshotService {
|
||||
systemd.services.proxy-suite-zapret = lib.mkIf zapretCfg.enable (mkOneshotService {
|
||||
description = "zapret2 DPI bypass";
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
|
||||
@@ -20,7 +20,7 @@ let
|
||||
table = "proxy_suite_cutoff_probe";
|
||||
# try-restart fails on a unit that is not installed, so only name the ones built.
|
||||
restartUnits =
|
||||
lib.optional cfg.zapret.enable "zapret-discord-youtube.service"
|
||||
lib.optional cfg.zapret.enable "proxy-suite-zapret.service"
|
||||
++ lib.optional cfg.perAppRouting.zapret.enable "proxy-suite-per-app-zapret.service";
|
||||
|
||||
z2kDetect = pkgs.buildGoModule {
|
||||
|
||||
@@ -93,14 +93,28 @@ let
|
||||
else
|
||||
pkgs.writeText "proxy-suite-zapret2" (lib.concatStringsSep " " source.blobArgs);
|
||||
|
||||
# The state layer undoes a rotation when the host succeeded within 30 s, unless
|
||||
# a failure came later; only z2k's own detector stamps that failure. Without the
|
||||
# stamp any success on a busy host (all of googlevideo.com) undoes every rotation.
|
||||
failStamp = pkgs.writeText "proxy-suite-zapret2-fail-stamp.lua" ''
|
||||
local count = automate_failure_counter
|
||||
function automate_failure_counter(hrec, crec, fails, maxtime)
|
||||
if not (crec and crec.failure) then
|
||||
hrec.z2k_last_fail_ts = type(clock_getfloattime) == "function" and clock_getfloattime() or os.time()
|
||||
end
|
||||
return count(hrec, crec, fails, maxtime)
|
||||
end
|
||||
'';
|
||||
|
||||
# The state layer wraps circular, so it loads after the source's Lua. z2k-tcp16
|
||||
# does nothing until the cutoff probe has written its maps.
|
||||
optPrefix = lib.concatStringsSep " " (
|
||||
map (file: "--lua-init=@${file}") (
|
||||
source.luaInit
|
||||
++ map (name: "${zapret2Sources.z2k}/files/lua/${name}.lua") [
|
||||
"z2k-tcp16"
|
||||
"z2k-state-persist"
|
||||
++ [
|
||||
"${zapret2Sources.z2k}/files/lua/z2k-tcp16.lua"
|
||||
failStamp
|
||||
"${zapret2Sources.z2k}/files/lua/z2k-state-persist.lua"
|
||||
]
|
||||
)
|
||||
++ lib.mapAttrsToList (name: file: "--blob=${name}:@${blobPath file}") zapret2Cfg.blobs
|
||||
|
||||
@@ -61,7 +61,11 @@ let
|
||||
# Its init script's order. QUIC reads the learned list but never adds to it:
|
||||
# browsers retry over TCP. The UDP profile carries no SNI, so no lists.
|
||||
profiles = [
|
||||
(args "NFQWS_ARGS_UDP")
|
||||
# Its first UDP strategy's fake has no blob, which zapret2 rejects on every
|
||||
# packet; nfqws1's default for unknown UDP was 64 zero bytes.
|
||||
(replaceStrings [ "--lua-desync=fake:repeats=6:strategy=1" ] [
|
||||
"--lua-desync=fake:blob=0x${lib.fixedWidthString 128 "0" ""}:repeats=6:strategy=1"
|
||||
] (args "NFQWS_ARGS_UDP"))
|
||||
"${args "NFQWS_ARGS_QUIC"} <HOSTLIST_NOAUTO> ${lists}"
|
||||
"${withSniPick (args "NFQWS_ARGS")} <HOSTLIST> ${lists}"
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user