luci: balancing add strategy option & remove unnesscary options

* luci: balancing add strategy option & remove unnesscary options

Signed-off-by: nftbty <nftbty@gmail.com>

* luci: add description for probeInterval option in balancing
Add description for the probeInterval option, from the official V2ray documentation.

---------

Signed-off-by: nftbty <nftbty@gmail.com>
This commit is contained in:
nftbty 2023-03-26 18:44:42 +08:00 committed by sbwml
parent 623099d837
commit 146648178c
3 changed files with 33 additions and 6 deletions

View File

@ -142,9 +142,18 @@ for k, e in ipairs(api.get_valid_nodes()) do
end end
-- 负载均衡列表 -- 负载均衡列表
balancing_node = s:option(DynamicList, "balancing_node", translate("Load balancing node list"), translate("Load balancing node list, <a target='_blank' href='https://toutyrater.github.io/routing/balance2.html'>document</a>")) local balancing_node = s:option(DynamicList, "balancing_node", translate("Load balancing node list"), translate("Load balancing node list, <a target='_blank' href='https://toutyrater.github.io/routing/balance2.html'>document</a>"))
for k, v in pairs(nodes_table) do balancing_node:value(v.id, v.remarks) end for k, v in pairs(nodes_table) do balancing_node:value(v.id, v.remarks) end
balancing_node:depends("protocol", "_balancing") 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 <code>ns</code>, <code>us</code>, <code>ms</code>, <code>s</code>, <code>m</code>, <code>h</code>, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively.")
-- 分流 -- 分流
uci:foreach(appname, "shunt_rules", function(e) uci:foreach(appname, "shunt_rules", function(e)
@ -205,13 +214,11 @@ domainStrategy.description = "<br /><ul><li>" .. translate("'AsIs': Only use dom
.. "</li><li>" .. translate("'IPIfNonMatch': When no rule matches current domain, resolves it into IP addresses (A or AAAA records) and try all rules again.") .. "</li><li>" .. translate("'IPIfNonMatch': When no rule matches current domain, resolves it into IP addresses (A or AAAA records) and try all rules again.")
.. "</li><li>" .. translate("'IPOnDemand': As long as there is a IP-based rule, resolves the domain into IP immediately.") .. "</li><li>" .. translate("'IPOnDemand': As long as there is a IP-based rule, resolves the domain into IP immediately.")
.. "</li></ul>" .. "</li></ul>"
domainStrategy:depends("protocol", "_balancing")
domainStrategy:depends("protocol", "_shunt") domainStrategy:depends("protocol", "_shunt")
domainMatcher = s:option(ListValue, "domainMatcher", translate("Domain matcher")) domainMatcher = s:option(ListValue, "domainMatcher", translate("Domain matcher"))
domainMatcher:value("hybrid") domainMatcher:value("hybrid")
domainMatcher:value("linear") domainMatcher:value("linear")
domainMatcher:depends("protocol", "_balancing")
domainMatcher:depends("protocol", "_shunt") domainMatcher:depends("protocol", "_shunt")

View File

@ -527,6 +527,7 @@ function gen_config(var)
local dns = nil local dns = nil
local fakedns = nil local fakedns = nil
local routing = nil local routing = nil
local observatory = nil
local inbounds = {} local inbounds = {}
local outbounds = {} local outbounds = {}
@ -791,10 +792,18 @@ function gen_config(var)
local outbound = gen_outbound(flag, node) local outbound = gen_outbound(flag, node)
if outbound then table.insert(outbounds, outbound) end if outbound then table.insert(outbounds, outbound) end
end end
if node.balancingStrategy == "leastPing" then
observatory = {
subjectSelector = nodes,
probeInterval = node.probeInterval or "1m"
}
end
routing = { routing = {
domainStrategy = node.domainStrategy or "AsIs", balancers = {{
domainMatcher = node.domainMatcher or "hybrid", tag = "balancer",
balancers = {{tag = "balancer", selector = nodes}}, selector = nodes,
strategy = {type = node.balancingStrategy or "random"}
}},
rules = { rules = {
{type = "field", network = "tcp,udp", balancerTag = "balancer"} {type = "field", network = "tcp,udp", balancerTag = "balancer"}
} }
@ -1039,6 +1048,8 @@ function gen_config(var)
inbounds = inbounds, inbounds = inbounds,
-- 传出连接 -- 传出连接
outbounds = outbounds, outbounds = outbounds,
-- 连接观测
observatory = observatory,
-- 路由 -- 路由
routing = routing, routing = routing,
-- 本地策略 -- 本地策略

View File

@ -346,6 +346,15 @@ msgstr "Xray 负载均衡"
msgid "V2ray_balancing" msgid "V2ray_balancing"
msgstr "V2ray 负载均衡" 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 <code>ns</code>, <code>us</code>, <code>ms</code>, <code>s</code>, <code>m</code>, <code>h</code>, which correspond to nanoseconds, microseconds, milliseconds, seconds, minutes, and hours, respectively."
msgstr "发起探测的间隔。每经过这个时间,就会对一个服务器进行服务器状态检测。时间格式为数字+单位,比如<code>&quot;10s&quot;</code>, <code>&quot;2h45m&quot;</code>,支持的时间单位有 <code>ns</code><code>us</code><code>ms</code><code>s</code><code>m</code><code>h</code>,分别对应纳秒、微秒、毫秒、秒、分、时。"
msgid "Shunt" msgid "Shunt"
msgstr "分流" msgstr "分流"