test: Add Tuic

This commit is contained in:
wyx2685
2025-04-30 07:50:41 +09:00
parent 6a95d576f1
commit d200a3336e
6 changed files with 46 additions and 2 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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{

View File

@@ -96,6 +96,7 @@ func (b *Sing) Protocols() []string {
"vless",
"shadowsocks",
"trojan",
"tuic",
"hysteria",
"hysteria2",
}

View File

@@ -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":

View File

@@ -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{