From d200a3336e96f162fd40e0e8aea4a8bf0854fb47 Mon Sep 17 00:00:00 2001 From: wyx2685 Date: Wed, 30 Apr 2025 07:50:41 +0900 Subject: [PATCH] test: Add Tuic --- api/panel/node.go | 16 ++++++++++++++++ api/panel/panel.go | 1 + core/sing/node.go | 11 +++++++++++ core/sing/sing.go | 1 + core/sing/user.go | 15 +++++++++++++++ node/task.go | 4 ++-- 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/api/panel/node.go b/api/panel/node.go index 120d867..e26c272 100644 --- a/api/panel/node.go +++ b/api/panel/node.go @@ -32,6 +32,7 @@ type NodeInfo struct { VAllss *VAllssNode Shadowsocks *ShadowsocksNode Trojan *TrojanNode + Tuic *TuicNode Hysteria *HysteriaNode Hysteria2 *Hysteria2Node Common *CommonNode @@ -100,6 +101,12 @@ type TrojanNode struct { NetworkSettings json.RawMessage `json:"networkSettings"` } +type TuicNode struct { + CommonNode + CongestionControl string `json:"congestion_control"` + ZeroRTTHandshake bool `json:"zero_rtt_handshake"` +} + type HysteriaNode struct { CommonNode UpMbps int `json:"up_mbps"` @@ -203,6 +210,15 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) { cm = &rsp.CommonNode node.Trojan = rsp node.Security = Tls + case "tuic": + rsp := &TuicNode{} + err = json.Unmarshal(r.Body(), rsp) + if err != nil { + return nil, fmt.Errorf("decode tuic params error: %s", err) + } + cm = &rsp.CommonNode + node.Tuic = rsp + node.Security = Tls case "hysteria": rsp := &HysteriaNode{} err = json.Unmarshal(r.Body(), rsp) diff --git a/api/panel/panel.go b/api/panel/panel.go index 61a9d69..2209032 100644 --- a/api/panel/panel.go +++ b/api/panel/panel.go @@ -56,6 +56,7 @@ func New(c *conf.ApiConfig) (*Client, error) { "shadowsocks", "hysteria", "hysteria2", + "tuic", "vless": default: return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType) diff --git a/core/sing/node.go b/core/sing/node.go index f75062e..e529901 100644 --- a/core/sing/node.go +++ b/core/sing/node.go @@ -343,6 +343,17 @@ func getInboundOptions(tag string, info *panel.NodeInfo, c *conf.Options) (optio } } in.Options = trojanoption + case "tuic": + in.Type = "tuic" + tls.ALPN = append(tls.ALPN, "h3") + in.Options = &option.TUICInboundOptions{ + ListenOptions: listen, + CongestionControl: info.Tuic.CongestionControl, + ZeroRTTHandshake: info.Tuic.ZeroRTTHandshake, + InboundTLSOptionsContainer: option.InboundTLSOptionsContainer{ + TLS: &tls, + }, + } case "hysteria": in.Type = "hysteria" in.Options = &option.HysteriaInboundOptions{ diff --git a/core/sing/sing.go b/core/sing/sing.go index c47deed..5c294f7 100644 --- a/core/sing/sing.go +++ b/core/sing/sing.go @@ -96,6 +96,7 @@ func (b *Sing) Protocols() []string { "vless", "shadowsocks", "trojan", + "tuic", "hysteria", "hysteria2", } diff --git a/core/sing/user.go b/core/sing/user.go index 7668c8e..2e87d73 100644 --- a/core/sing/user.go +++ b/core/sing/user.go @@ -12,6 +12,7 @@ import ( "github.com/sagernet/sing-box/protocol/hysteria2" "github.com/sagernet/sing-box/protocol/shadowsocks" "github.com/sagernet/sing-box/protocol/trojan" + "github.com/sagernet/sing-box/protocol/tuic" "github.com/sagernet/sing-box/protocol/vless" "github.com/sagernet/sing-box/protocol/vmess" ) @@ -66,6 +67,18 @@ func (b *Sing) AddUsers(p *core.AddUsersParams) (added int, err error) { } } err = in.(*trojan.Inbound).AddUsers(us) + case "tuic": + us := make([]option.TUICUser, len(p.Users)) + id := make([]int, len(p.Users)) + for i := range p.Users { + us[i] = option.TUICUser{ + Name: p.Users[i].Uuid, + UUID: p.Users[i].Uuid, + Password: p.Users[i].Uuid, + } + id[i] = p.Users[i].Id + } + err = in.(*tuic.Inbound).AddUsers(us, id) case "hysteria": us := make([]option.HysteriaUser, len(p.Users)) for i := range p.Users { @@ -122,6 +135,8 @@ func (b *Sing) DelUsers(users []panel.UserInfo, tag string, info *panel.NodeInfo del = i.(*shadowsocks.MultiInbound) case "trojan": del = i.(*trojan.Inbound) + case "tuic": + del = i.(*tuic.Inbound) case "hysteria": del = i.(*hysteria.Inbound) case "hysteria2": diff --git a/node/task.go b/node/task.go index f70ccb1..291c85b 100644 --- a/node/task.go +++ b/node/task.go @@ -91,7 +91,7 @@ func (c *Controller) nodeInfoMonitor() (err error) { log.WithFields(log.Fields{ "tag": c.tag, "err": err, - }).Error("Delete node failed") + }).Panic("Delete node failed") return nil } @@ -135,7 +135,7 @@ func (c *Controller) nodeInfoMonitor() (err error) { log.WithFields(log.Fields{ "tag": c.tag, "err": err, - }).Error("Add node failed") + }).Panic("Add node failed") return nil } _, err = c.server.AddUsers(&vCore.AddUsersParams{