add quic support and fixed some bug

This commit is contained in:
MengXin239 2024-06-09 17:58:22 +08:00
parent 9261a6063d
commit 175e46d0b7
8 changed files with 85 additions and 45 deletions

View File

@ -37,25 +37,47 @@ type NodeStatus struct {
} }
type NodeInfo struct { type NodeInfo struct {
NodeType string // Must be V2ray, Trojan, and Shadowsocks AcceptProxyProtocol bool
NodeID int Authority string
Port uint32 NodeType string // Must be V2ray, Trojan, and Shadowsocks
SpeedLimit uint64 // Bps NodeID int
AlterID uint16 Port uint32
TransportProtocol string SpeedLimit uint64 // Bps
FakeType string AlterID uint16
Host string TransportProtocol string
Path string FakeType string
EnableTLS bool Host string
EnableVless bool Path string
VlessFlow string EnableTLS bool
CypherMethod string EnableSniffing bool
ServerKey string RouteOnly bool
ServiceName string EnableVless bool
Header json.RawMessage VlessFlow string
NameServerConfig []*conf.NameServerConfig CypherMethod string
EnableREALITY bool ServerKey string
REALITYConfig *REALITYConfig ServiceName string
Method string
Header json.RawMessage
HttpHeaders map[string]*conf.StringList
Headers map[string]string
NameServerConfig []*conf.NameServerConfig
EnableREALITY bool
REALITYConfig *REALITYConfig
Show bool
EnableTFO bool
Dest string
ProxyProtocolVer uint64
ServerNames []string
PrivateKey string
MinClientVer string
MaxClientVer string
MaxTimeDiff uint64
ShortIds []string
Xver uint64
Flow string
Security string
Key string
RejectUnknownSni bool
} }
type UserInfo struct { type UserInfo struct {

View File

@ -177,7 +177,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
c.resp.Store(server) c.resp.Store(server)
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
nodeInfo, err = c.parseV2rayNodeResponse(server) nodeInfo, err = c.parseV2rayNodeResponse(server)
case "Trojan": case "Trojan":
nodeInfo, err = c.parseTrojanNodeResponse(server) nodeInfo, err = c.parseTrojanNodeResponse(server)
@ -200,7 +200,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
path := "/api/server/user" path := "/api/server/user"
switch c.NodeType { switch c.NodeType {
case "V2ray", "Trojan", "Shadowsocks": case "V2ray", "Trojan", "Shadowsocks", "Vmess", "Vless":
break break
default: default:
return nil, fmt.Errorf("unsupported node type: %s", c.NodeType) return nil, fmt.Errorf("unsupported node type: %s", c.NodeType)

View File

@ -184,7 +184,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
c.resp.Store(server) c.resp.Store(server)
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
nodeInfo, err = c.parseV2rayNodeResponse(server) nodeInfo, err = c.parseV2rayNodeResponse(server)
case "Trojan": case "Trojan":
nodeInfo, err = c.parseTrojanNodeResponse(server) nodeInfo, err = c.parseTrojanNodeResponse(server)
@ -207,7 +207,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
path := "/api/v1/server/UniProxy/user" path := "/api/v1/server/UniProxy/user"
switch c.NodeType { switch c.NodeType {
case "V2ray", "Trojan", "Shadowsocks": case "V2ray", "Trojan", "Shadowsocks", "Vmess", "Vless":
break break
default: default:
return nil, fmt.Errorf("unsupported node type: %s", c.NodeType) return nil, fmt.Errorf("unsupported node type: %s", c.NodeType)

View File

@ -145,7 +145,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/node/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/node/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/node/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/node/%d", c.NodeID)
@ -166,7 +166,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
} }
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
nodeInfo, err = c.ParseV2rayNodeResponse(&response.Data) nodeInfo, err = c.ParseV2rayNodeResponse(&response.Data)
case "Trojan": case "Trojan":
nodeInfo, err = c.ParseTrojanNodeResponse(&response.Data) nodeInfo, err = c.ParseTrojanNodeResponse(&response.Data)
@ -188,7 +188,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/userList/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/userList/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/userList/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/userList/%d", c.NodeID)
@ -209,7 +209,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
} }
userList := new([]api.UserInfo) userList := new([]api.UserInfo)
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
userList, err = c.ParseV2rayUserListResponse(&response.Data) userList, err = c.ParseV2rayUserListResponse(&response.Data)
case "Trojan": case "Trojan":
userList, err = c.ParseTrojanUserListResponse(&response.Data) userList, err = c.ParseTrojanUserListResponse(&response.Data)
@ -229,7 +229,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) { func (c *APIClient) ReportNodeStatus(nodeStatus *api.NodeStatus) (err error) {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/nodeStatus/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/nodeStatus/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/nodeStatus/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/nodeStatus/%d", c.NodeID)
@ -265,7 +265,7 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/nodeOnline/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/nodeOnline/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/nodeOnline/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/nodeOnline/%d", c.NodeID)
@ -298,7 +298,7 @@ func (c *APIClient) ReportNodeOnlineUsers(onlineUserList *[]api.OnlineUser) erro
func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error { func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/userTraffic/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/userTraffic/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/userTraffic/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/userTraffic/%d", c.NodeID)
@ -333,7 +333,7 @@ func (c *APIClient) ReportUserTraffic(userTraffic *[]api.UserTraffic) error {
func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) { func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/nodeRule/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/nodeRule/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/nodeRule/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/nodeRule/%d", c.NodeID)
@ -381,7 +381,7 @@ func (c *APIClient) GetNodeRule() (*[]api.DetectRule, error) {
func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error { func (c *APIClient) ReportIllegal(detectResultList *[]api.DetectResult) error {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
path = fmt.Sprintf("/api/v2ray/v1/trigger/%d", c.NodeID) path = fmt.Sprintf("/api/v2ray/v1/trigger/%d", c.NodeID)
case "Trojan": case "Trojan":
path = fmt.Sprintf("/api/trojan/v1/trigger/%d", c.NodeID) path = fmt.Sprintf("/api/trojan/v1/trigger/%d", c.NodeID)

View File

@ -151,7 +151,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) (
func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
var nodeType string var nodeType string
switch c.NodeType { switch c.NodeType {
case "V2ray", "Trojan", "Shadowsocks": case "V2ray", "Vmess", "Vless", "Trojan", "Shadowsocks":
nodeType = strings.ToLower(c.NodeType) nodeType = strings.ToLower(c.NodeType)
default: default:
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType) return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
@ -183,7 +183,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
} }
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
nodeInfo, err = c.ParseV2rayNodeResponse(response) nodeInfo, err = c.ParseV2rayNodeResponse(response)
case "Trojan": case "Trojan":
nodeInfo, err = c.ParseTrojanNodeResponse(response) nodeInfo, err = c.ParseTrojanNodeResponse(response)
@ -205,7 +205,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) {
func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
var nodeType string var nodeType string
switch c.NodeType { switch c.NodeType {
case "V2ray", "Trojan", "Shadowsocks": case "V2ray", "Vmess", "Vless", "Trojan", "Shadowsocks":
nodeType = strings.ToLower(c.NodeType) nodeType = strings.ToLower(c.NodeType)
default: default:
return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType) return nil, fmt.Errorf("unsupported Node type: %s", c.NodeType)
@ -249,7 +249,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString() user.Email = response.Get("data").GetIndex(i).Get("trojan_user").Get("password").MustString()
user.SpeedLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8 user.SpeedLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("speed_limit").MustUint64() * 1000000 / 8
user.DeviceLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("device_limit").MustInt() user.DeviceLimit = response.Get("data").GetIndex(i).Get("trojan_user").Get("device_limit").MustInt()
case "V2ray": case "V2ray", "Vmess", "Vless":
user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString() user.UUID = response.Get("data").GetIndex(i).Get("v2ray_user").Get("uuid").MustString()
user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString() user.Email = response.Get("data").GetIndex(i).Get("v2ray_user").Get("email").MustString()
user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64()) user.AlterID = uint16(response.Get("data").GetIndex(i).Get("v2ray_user").Get("alter_id").MustUint64())
@ -263,7 +263,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) {
if c.DeviceLimit > 0 { if c.DeviceLimit > 0 {
user.DeviceLimit = c.DeviceLimit user.DeviceLimit = c.DeviceLimit
} }
userList[i] = user userList[i] = user
} }
return &userList, nil return &userList, nil

View File

@ -18,7 +18,7 @@ Nodes:
ApiHost: "http://127.0.0.1:667" ApiHost: "http://127.0.0.1:667"
ApiKey: "123" ApiKey: "123"
NodeID: 41 NodeID: 41
NodeType: V2ray # Node type: V2ray, Shadowsocks, Trojan, Shadowsocks-Plugin NodeType: V2ray # Node type: V2ray,vmess,vless, Shadowsocks, Trojan, Shadowsocks-Plugin
Timeout: 30 # Timeout for the api request Timeout: 30 # Timeout for the api request
EnableVless: false # Enable Vless for V2ray Type EnableVless: false # Enable Vless for V2ray Type
VlessFlow: "xtls-rprx-vision" # Only support vless VlessFlow: "xtls-rprx-vision" # Only support vless

View File

@ -405,7 +405,7 @@ func (c *Controller) addInboundForSSPlugin(newNodeInfo api.NodeInfo) (err error)
func (c *Controller) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo) (err error) { func (c *Controller) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo) (err error) {
users := make([]*protocol.User, 0) users := make([]*protocol.User, 0)
switch nodeInfo.NodeType { switch nodeInfo.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
if nodeInfo.EnableVless { if nodeInfo.EnableVless {
users = c.buildVlessUser(userInfo) users = c.buildVlessUser(userInfo)
} else { } else {

View File

@ -41,7 +41,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
// SniffingConfig // SniffingConfig
sniffingConfig := &conf.SniffingConfig{ sniffingConfig := &conf.SniffingConfig{
Enabled: true, Enabled: true,
DestOverride: &conf.StringList{"http", "tls"}, DestOverride: &conf.StringList{"http", "tls", "quic", "fakedns"},
} }
if config.DisableSniffing { if config.DisableSniffing {
sniffingConfig.Enabled = false sniffingConfig.Enabled = false
@ -57,8 +57,8 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
var proxySetting any var proxySetting any
// Build Protocol and Protocol setting // Build Protocol and Protocol setting
switch nodeInfo.NodeType { switch nodeInfo.NodeType {
case "V2ray": case "V2ray", "Vmess", "Vless":
if nodeInfo.EnableVless { if nodeInfo.EnableVless || nodeInfo.NodeType == "Vless" {
protocol = "vless" protocol = "vless"
// Enable fallback // Enable fallback
if config.EnableFallback { if config.EnableFallback {
@ -164,6 +164,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
headers["Host"] = nodeInfo.Host headers["Host"] = nodeInfo.Host
wsSettings := &conf.WebSocketConfig{ wsSettings := &conf.WebSocketConfig{
AcceptProxyProtocol: config.EnableProxyProtocol, AcceptProxyProtocol: config.EnableProxyProtocol,
Host: nodeInfo.Host,
Path: nodeInfo.Path, Path: nodeInfo.Path,
Headers: headers, Headers: headers,
} }
@ -171,17 +172,34 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I
case "http": case "http":
hosts := conf.StringList{nodeInfo.Host} hosts := conf.StringList{nodeInfo.Host}
httpSettings := &conf.HTTPConfig{ httpSettings := &conf.HTTPConfig{
Host: &hosts, Host: &hosts,
Path: nodeInfo.Path, Path: nodeInfo.Path,
Method: nodeInfo.Method,
Headers: nodeInfo.HttpHeaders,
} }
streamSetting.HTTPSettings = httpSettings streamSetting.HTTPSettings = httpSettings
case "grpc": case "grpc":
grpcSettings := &conf.GRPCConfig{ grpcSettings := &conf.GRPCConfig{
ServiceName: nodeInfo.ServiceName, ServiceName: nodeInfo.ServiceName,
Authority: nodeInfo.Authority,
} }
streamSetting.GRPCConfig = grpcSettings streamSetting.GRPCConfig = grpcSettings
case "quic":
quicSettings := &conf.QUICConfig{
Header: nodeInfo.Header,
Security: nodeInfo.Security,
Key: nodeInfo.Key,
}
streamSetting.QUICSettings = quicSettings
case "httpupgrade":
httpupgradeSettings := &conf.HttpUpgradeConfig{
Headers: nodeInfo.Headers,
Path: nodeInfo.Path,
Host: nodeInfo.Host,
AcceptProxyProtocol: nodeInfo.AcceptProxyProtocol,
}
streamSetting.HTTPUPGRADESettings = httpupgradeSettings
} }
streamSetting.Network = &transportProtocol streamSetting.Network = &transportProtocol
// Build TLS and REALITY settings // Build TLS and REALITY settings