Skip to content

Commit

Permalink
luci: add sing-box TCP Brutal support (xiaorouji#2887)
Browse files Browse the repository at this point in the history
* luci: add sing-box TCP Brutal support
  • Loading branch information
Gzxhwq authored Dec 3, 2023
1 parent 0716c8a commit 761f6ec
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,6 @@ o = s:option(Flag, option_name("mux"), translate("Mux"))
o.rmempty = false
o:depends({ [option_name("protocol")] = "vmess" })
o:depends({ [option_name("protocol")] = "vless", [option_name("flow")] = "" })
o:depends({ [option_name("protocol")] = "http" })
o:depends({ [option_name("protocol")] = "socks" })
o:depends({ [option_name("protocol")] = "shadowsocks", [option_name("uot")] = "" })
o:depends({ [option_name("protocol")] = "trojan" })

Expand All @@ -554,13 +552,26 @@ o:value("h2mux")
o:depends({ [option_name("mux")] = true })

o = s:option(Value, option_name("mux_concurrency"), translate("Mux concurrency"))
o.default = 8
o:depends({ [option_name("mux")] = true })
o.default = 4
o:depends({ [option_name("mux")] = true, [option_name("tcpbrutal")] = false })

o = s:option(Flag, option_name("mux_padding"), translate("Padding"))
o.default = 0
o:depends({ [option_name("mux")] = true })

-- [[ TCP Brutal ]]--
o = s:option(Flag, option_name("tcpbrutal"), translate("TCP Brutal"))
o.default = 0
o:depends({ [option_name("mux")] = true })

o = s:option(Value, option_name("tcpbrutal_up_mbps"), translate("Max upload Mbps"))
o.default = "10"
o:depends({ [option_name("tcpbrutal")] = true })

o = s:option(Value, option_name("tcpbrutal_down_mbps"), translate("Max download Mbps"))
o.default = "50"
o:depends({ [option_name("tcpbrutal")] = true })

o = s:option(Flag, option_name("shadowtls"), "ShadowTLS")
o.default = 0
o:depends({ [option_name("protocol")] = "vmess", [option_name("tls")] = false })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,27 @@ o:depends({ [option_name("transport")] = "httpupgrade" })
o = s:option(Value, option_name("grpc_serviceName"), "ServiceName")
o:depends({ [option_name("transport")] = "grpc" })

-- [[ Mux ]]--
o = s:option(Flag, option_name("mux"), translate("Mux"))
o.rmempty = false
o:depends({ [option_name("protocol")] = "vmess" })
o:depends({ [option_name("protocol")] = "vless", [option_name("flow")] = "" })
o:depends({ [option_name("protocol")] = "shadowsocks" })
o:depends({ [option_name("protocol")] = "trojan" })

-- [[ TCP Brutal ]]--
o = s:option(Flag, option_name("tcpbrutal"), translate("TCP Brutal"))
o.default = 0
o:depends({ [option_name("mux")] = true })

o = s:option(Value, option_name("tcpbrutal_up_mbps"), translate("Max upload Mbps"))
o.default = "10"
o:depends({ [option_name("tcpbrutal")] = true })

o = s:option(Value, option_name("tcpbrutal_down_mbps"), translate("Max download Mbps"))
o.default = "50"
o:depends({ [option_name("tcpbrutal")] = true })

o = s:option(Flag, option_name("bind_local"), translate("Bind Local"), translate("When selected, it can only be accessed locally, It is recommended to turn on when using reverse proxies or be fallback."))
o.default = "0"

Expand Down
24 changes: 23 additions & 1 deletion luci-app-passwall/luasrc/passwall/util_sing-box.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@ function gen_outbound(flag, node, tag, proxy_table)
mux = {
enabled = true,
protocol = node.mux_type or "h2mux",
max_connections = tonumber(node.mux_concurrency) or 4,
max_connections = ( (node.tcpbrutal == "1") and 1 ) or tonumber(node.mux_concurrency) or 4,
padding = (node.mux_padding == "1") and true or false,
--min_streams = 4,
--max_streams = 0,
brutal = {
enabled = (node.tcpbrutal == "1") and true or false,
up_mbps = tonumber(node.tcpbrutal_up_mbps) or 10,
down_mbps = tonumber(node.tcpbrutal_down_mbps) or 50,
},
}
end

Expand Down Expand Up @@ -410,6 +415,19 @@ function gen_config_server(node)
}
end

local mux = nil
if node.mux == "1" then
mux = {
enabled = true,
padding = (node.mux_padding == "1") and true or false,
brutal = {
enabled = (node.tcpbrutal == "1") and true or false,
up_mbps = tonumber(node.tcpbrutal_up_mbps) or 10,
down_mbps = tonumber(node.tcpbrutal_down_mbps) or 50,
},
}
end

local v2ray_transport = nil

if node.transport == "http" then
Expand Down Expand Up @@ -499,6 +517,7 @@ function gen_config_server(node)
protocol_table = {
method = node.method,
password = node.password,
multiplex = mux,
}
end

Expand All @@ -515,6 +534,7 @@ function gen_config_server(node)
protocol_table = {
users = users,
tls = (node.tls == "1") and tls or nil,
multiplex = mux,
transport = v2ray_transport,
}
end
Expand All @@ -533,6 +553,7 @@ function gen_config_server(node)
protocol_table = {
users = users,
tls = (node.tls == "1") and tls or nil,
multiplex = mux,
transport = v2ray_transport,
}
end
Expand All @@ -552,6 +573,7 @@ function gen_config_server(node)
tls = (node.tls == "1") and tls or nil,
fallback = nil,
fallback_for_alpn = nil,
multiplex = mux,
transport = v2ray_transport,
}
end
Expand Down

0 comments on commit 761f6ec

Please sign in to comment.