From 146648178c5081f3177527f028cad10abc2138f0 Mon Sep 17 00:00:00 2001 From: nftbty Date: Sun, 26 Mar 2023 18:44:42 +0800 Subject: [PATCH] luci: balancing add strategy option & remove unnesscary options * luci: balancing add strategy option & remove unnesscary options Signed-off-by: nftbty * luci: add description for probeInterval option in balancing Add description for the probeInterval option, from the official V2ray documentation. --------- Signed-off-by: nftbty --- .../model/cbi/passwall/client/node_config.lua | 13 ++++++++++--- luci-app-passwall/luasrc/passwall/util_xray.lua | 17 ++++++++++++++--- luci-app-passwall/po/zh-cn/passwall.po | 9 +++++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua index 05ef2d43b..3540ef09c 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/client/node_config.lua @@ -142,9 +142,18 @@ for k, e in ipairs(api.get_valid_nodes()) do end -- 负载均衡列表 -balancing_node = s:option(DynamicList, "balancing_node", translate("Load balancing node list"), translate("Load balancing node list, document")) +local balancing_node = s:option(DynamicList, "balancing_node", translate("Load balancing node list"), translate("Load balancing node list, document")) for k, v in pairs(nodes_table) do balancing_node:value(v.id, v.remarks) end balancing_node:depends("protocol", "_balancing") +local balancingStrategy = s:option(ListValue, "balancingStrategy", translate("Balancing Strategy")) +balancingStrategy:depends("protocol", "_balancing") +balancingStrategy:value("random") +balancingStrategy:value("leastPing") +balancingStrategy.default = "random" +local probeInterval = s:option(Value, "probeInterval", translate("Probe Interval")) +probeInterval:depends("balancingStrategy", "leastPing") +probeInterval.default = "1m" +probeInterval.description = translate("The interval between initiating probes. Every time this time elapses, a server status check is performed on a server. The time format is numbers + units, such as '10s', '2h45m', and the supported time units are ns, us, ms, s, m, h, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively.") -- 分流 uci:foreach(appname, "shunt_rules", function(e) @@ -205,13 +214,11 @@ domainStrategy.description = "
  • " .. translate("'AsIs': Only use dom .. "
  • " .. translate("'IPIfNonMatch': When no rule matches current domain, resolves it into IP addresses (A or AAAA records) and try all rules again.") .. "
  • " .. translate("'IPOnDemand': As long as there is a IP-based rule, resolves the domain into IP immediately.") .. "
" -domainStrategy:depends("protocol", "_balancing") domainStrategy:depends("protocol", "_shunt") domainMatcher = s:option(ListValue, "domainMatcher", translate("Domain matcher")) domainMatcher:value("hybrid") domainMatcher:value("linear") -domainMatcher:depends("protocol", "_balancing") domainMatcher:depends("protocol", "_shunt") diff --git a/luci-app-passwall/luasrc/passwall/util_xray.lua b/luci-app-passwall/luasrc/passwall/util_xray.lua index bacdcb5d3..bf3c6c2de 100644 --- a/luci-app-passwall/luasrc/passwall/util_xray.lua +++ b/luci-app-passwall/luasrc/passwall/util_xray.lua @@ -527,6 +527,7 @@ function gen_config(var) local dns = nil local fakedns = nil local routing = nil + local observatory = nil local inbounds = {} local outbounds = {} @@ -791,10 +792,18 @@ function gen_config(var) local outbound = gen_outbound(flag, node) if outbound then table.insert(outbounds, outbound) end end + if node.balancingStrategy == "leastPing" then + observatory = { + subjectSelector = nodes, + probeInterval = node.probeInterval or "1m" + } + end routing = { - domainStrategy = node.domainStrategy or "AsIs", - domainMatcher = node.domainMatcher or "hybrid", - balancers = {{tag = "balancer", selector = nodes}}, + balancers = {{ + tag = "balancer", + selector = nodes, + strategy = {type = node.balancingStrategy or "random"} + }}, rules = { {type = "field", network = "tcp,udp", balancerTag = "balancer"} } @@ -1039,6 +1048,8 @@ function gen_config(var) inbounds = inbounds, -- 传出连接 outbounds = outbounds, + -- 连接观测 + observatory = observatory, -- 路由 routing = routing, -- 本地策略 diff --git a/luci-app-passwall/po/zh-cn/passwall.po b/luci-app-passwall/po/zh-cn/passwall.po index 850b1b0f6..3a28ad88e 100644 --- a/luci-app-passwall/po/zh-cn/passwall.po +++ b/luci-app-passwall/po/zh-cn/passwall.po @@ -346,6 +346,15 @@ msgstr "Xray 负载均衡" msgid "V2ray_balancing" msgstr "V2ray 负载均衡" +msgid "Balancing Strategy" +msgstr "负载均衡策略" + +msgid "Probe Interval" +msgstr "探测间隔" + +msgid "The interval between initiating probes. Every time this time elapses, a server status check is performed on a server. The time format is numbers + units, such as '10s', '2h45m', and the supported time units are ns, us, ms, s, m, h, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively." +msgstr "发起探测的间隔。每经过这个时间,就会对一个服务器进行服务器状态检测。时间格式为数字+单位,比如"10s", "2h45m",支持的时间单位有 nsusmssmh,分别对应纳秒、微秒、毫秒、秒、分、时。" + msgid "Shunt" msgstr "分流"