From 292b2f746f2fb8b71727bc722df474c09958c1a7 Mon Sep 17 00:00:00 2001 From: xiaorouji <60100640+xiaorouji@users.noreply.github.com> Date: Wed, 6 Sep 2023 16:18:07 +0800 Subject: [PATCH] luci: add TUIC support to sing-box server --- .../cbi/passwall/server/type/sing-box.lua | 25 +++++++++++++++++++ .../luasrc/passwall/util_sing-box.lua | 16 ++++++++++++ 2 files changed, 41 insertions(+) diff --git a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua index 5634c2682..44eefa99a 100644 --- a/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua +++ b/luci-app-passwall/luasrc/model/cbi/passwall/server/type/sing-box.lua @@ -59,6 +59,9 @@ o:value("naive", "Naive") if singbox_tags:find("with_quic") then o:value("hysteria", "Hysteria") end +if singbox_tags:find("with_quic") then + o:value("tuic", "TUIC") +end o:value("direct", "Direct") o = s:option(Value, option_name("port"), translate("Listen Port")) @@ -88,6 +91,7 @@ o.password = true o:depends({ [option_name("auth")] = true }) o:depends({ [option_name("protocol")] = "shadowsocks" }) o:depends({ [option_name("protocol")] = "naive" }) +o:depends({ [option_name("protocol")] = "tuic" }) if singbox_tags:find("with_quic") then o = s:option(Value, option_name("hysteria_up_mbps"), translate("Max upload Mbps")) @@ -129,6 +133,24 @@ if singbox_tags:find("with_quic") then o:depends({ [option_name("protocol")] = "hysteria" }) end +if singbox_tags:find("with_quic") then + o = s:option(ListValue, option_name("tuic_congestion_control"), translate("Congestion control algorithm")) + o.default = "cubic" + o:value("bbr", translate("BBR")) + o:value("cubic", translate("CUBIC")) + o:value("new_reno", translate("New Reno")) + o:depends({ [option_name("protocol")] = "tuic" }) + + o = s:option(Flag, option_name("tuic_zero_rtt_handshake"), translate("Enable 0-RTT QUIC handshake")) + o.default = 0 + o:depends({ [option_name("protocol")] = "tuic" }) + + o = s:option(Value, option_name("tuic_heartbeat"), translate("Heartbeat interval(second)")) + o.datatype = "uinteger" + o.default = "3" + o:depends({ [option_name("protocol")] = "tuic" }) +end + o = s:option(ListValue, option_name("d_protocol"), translate("Destination protocol")) o:value("tcp", "TCP") o:value("udp", "UDP") @@ -166,6 +188,7 @@ end o:depends({ [option_name("protocol")] = "vmess" }) o:depends({ [option_name("protocol")] = "vless" }) o:depends({ [option_name("protocol")] = "trojan" }) +o:depends({ [option_name("protocol")] = "tuic" }) o = s:option(ListValue, option_name("flow"), translate("flow")) o.default = "" @@ -199,6 +222,7 @@ o = s:option(FileUpload, option_name("tls_certificateFile"), translate("Public k o.default = m:get(s.section, "tls_certificateFile") or "/etc/config/ssl/" .. arg[1] .. ".pem" o:depends({ [option_name("tls")] = true }) o:depends({ [option_name("protocol")] = "hysteria" }) +o:depends({ [option_name("protocol")] = "tuic" }) o.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then @@ -214,6 +238,7 @@ o = s:option(FileUpload, option_name("tls_keyFile"), translate("Private key abso o.default = m:get(s.section, "tls_keyFile") or "/etc/config/ssl/" .. arg[1] .. ".key" o:depends({ [option_name("tls")] = true }) o:depends({ [option_name("protocol")] = "hysteria" }) +o:depends({ [option_name("protocol")] = "tuic" }) o.validate = function(self, value, t) if value and value ~= "" then if not nixio.fs.access(value) then diff --git a/luci-app-passwall/luasrc/passwall/util_sing-box.lua b/luci-app-passwall/luasrc/passwall/util_sing-box.lua index 0a3e94a07..b90f67269 100644 --- a/luci-app-passwall/luasrc/passwall/util_sing-box.lua +++ b/luci-app-passwall/luasrc/passwall/util_sing-box.lua @@ -524,6 +524,22 @@ function gen_config_server(node) } end + if node.protocol == "tuic" then + protocol_table = { + users = { + { + name = "user1", + uuid = node.uuid, + password = node.password + } + }, + congestion_control = node.tuic_congestion_control or "cubic", + zero_rtt_handshake = (node.tuic_zero_rtt_handshake == "1") and true or false, + heartbeat = node.tuic_heartbeat .. "s", + tls = tls, + } + end + if node.protocol == "direct" then protocol_table = { network = (node.d_protocol ~= "TCP,UDP") and node.d_protocol or nil,