feat: xhttp xmux

This commit is contained in:
FUFSoB committed 2026-10-18 16:53:08 +05:00
1 parent 2fc8ef5567
commit a41fbc10e6
16 files changed
+231 -18

No files matched your search

+7
View File
@@ -644,6 +644,12 @@ let
}
.${cfg.debug.logLevel};
connectionLogEnabled = cfg.enable && clashApiEnabled && cfg.debug.connectionLog.enable;
# proxy.xray.xhttpXmux, as a jq step over one XRay outbound: an XHTTP one whose link set no
# xmux takes it. JSON is a jq literal.
xhttpXmuxJq = lib.optionalString (xrayCfg.xhttpXmux != null) ''
| if .streamSettings.network? == "xhttp" and ((.streamSettings.xhttpSettings.extra.xmux? // {}) == {})
then .streamSettings.xhttpSettings.extra.xmux = ${builtins.toJSON xrayCfg.xhttpXmux}
else . end'';
perAppZapretEnabled = perAppZapretCfg.enable;
# The global units each per-app backend steps aside for (constants.refuseUnderGlobal), as
# systemctl patterns: they stop it as they start, and the standby unit waits them out.
@@ -1260,6 +1266,7 @@ in
singBoxLogLevel
xrayLogLevel
connectionLogEnabled
xhttpXmuxJq
singBoxCfg
xrayCfg
proxyEnabled
+22
View File
@@ -195,6 +195,28 @@ in
example = literalExpression "pkgs.xray";
description = ''XRay package, for the "xray" and "hybrid" backends.'';
};
xhttpXmux = mkOption {
# A number, or a range XRay picks from at random.
type = types.nullOr (types.attrsOf (types.either types.int (types.strMatching "[0-9]+(-[0-9]+)?")));
default = null;
description = ''
XRay's `xmux` for every XHTTP outbound whose link sets none (in its `extra`): how
its connections are spread over HTTP/2 or HTTP/3 connections to the server, and how
soon a dead one is noticed. XRay notices a connection that stopped answering only by
`hKeepAlivePeriod`'s ping: after that many seconds without a frame, plus 15 for the
ping, default 45, so a minute in which everything on it hangs, new connections too.
XRay applies its own defaults (`maxConnections` 3, `hMaxRequestTimes` "600-900",
`hMaxReusableSecs` "1800-3000") only to an empty `xmux`: give them here too.
`null`: XRay's defaults.
'';
example = {
maxConnections = 3;
hMaxRequestTimes = "600-900";
hMaxReusableSecs = "1800-3000";
hKeepAlivePeriod = 10;
};
};
};
};
}
@@ -46,6 +46,8 @@ def xray_pin_server_names:
# Slurped (a list of one), not an argument: it grows with the rules.
$route_rules[0] as $route_rules
| .outbounds = ($obs[0] + .outbounds)
# proxy.xray.xhttpXmux.
| .outbounds |= map(. @setXhttpXmux@)
| if $xray_loglevel == "" then . else .log.loglevel = $xray_loglevel end
| if $auth_enabled then
(.inbounds[] | select(.protocol == "socks" and .tag == "mixed-in") | .settings.auth) = "password"
@@ -15,6 +15,8 @@
awgRuntimeDnsServer ? null,
# proxy.listener on an address other machines reach (0.0.0.0, a LAN address).
listenerExposed ? false,
# derived.xhttpXmuxJq.
xhttpXmuxJq ? "",
}:
let
@@ -60,6 +62,7 @@ if pureXrayEnabled then
(fillTemplate ./backend-filter-xray.template.jq {
inherit selectionMode;
hostClosedPorts = lib.concatStringsSep "," closedPorts;
setXhttpXmux = xhttpXmuxJq;
})
else
(fillTemplate ./backend-filter-sing-box.template.jq {
@@ -7,6 +7,7 @@ let
jq
hybridEnabled
xraySidecarRoutingMark
xhttpXmuxJq
;
in
@@ -21,6 +22,7 @@ lib.optionalString hybridEnabled (
setSidecarMark = lib.optionalString (
xraySidecarRoutingMark != null
) "| .streamSettings.sockopt.mark = $mark";
setXhttpXmux = xhttpXmuxJq;
hopRoutingMark = lib.optionalString (
routingMark != null
) " + {routing_mark: ${toString routingMark}}";
@@ -30,6 +30,7 @@ _proxy_suite_add_xray_sidecar_obs() {
| .value.tag as $tag
| {outbound: (.value
@setSidecarMark@
@setXhttpXmux@
| .streamSettings.sockopt.domainStrategy = (.streamSettings.sockopt.domainStrategy // "UseIP")),
client: {id: $id, email: $tag},
rule: {type: "field", inboundTag: ["sidecar-in"], user: [$tag], outboundTag: $tag},
+1 -1
View File
@@ -167,7 +167,7 @@ let
proxyInboundsGuardStrategy
;
proxyInboundsBlockPrivate = proxyInboundsCfg.routing.blockPrivate;
inherit (ctx) proxyInboundsLoopback proxyInboundsHostClosedPorts;
inherit (ctx) proxyInboundsLoopback proxyInboundsHostClosedPorts xhttpXmuxJq;
listenerExposed =
let
address = proxyCfg.listener.address;