From 175e46d0b7ba0e29e3560c86854455807f13a91e Mon Sep 17 00:00:00 2001 From: MengXin239 Date: Sun, 9 Jun 2024 17:58:22 +0800 Subject: [PATCH] add quic support and fixed some bug --- api/apimodel.go | 60 +++++++++++++++++++--------- api/gov2panel/gov2panel.go | 4 +- api/newV2board/v2board.go | 4 +- api/proxypanel/proxypanel.go | 18 ++++----- api/v2raysocks/v2raysocks.go | 10 ++--- release/config/config.yml.example | 2 +- service/controller/controller.go | 2 +- service/controller/inboundbuilder.go | 30 +++++++++++--- 8 files changed, 85 insertions(+), 45 deletions(-) diff --git a/api/apimodel.go b/api/apimodel.go index 58104be9..4a6c4491 100644 --- a/api/apimodel.go +++ b/api/apimodel.go @@ -37,25 +37,47 @@ type NodeStatus struct { } type NodeInfo struct { - NodeType string // Must be V2ray, Trojan, and Shadowsocks - NodeID int - Port uint32 - SpeedLimit uint64 // Bps - AlterID uint16 - TransportProtocol string - FakeType string - Host string - Path string - EnableTLS bool - EnableVless bool - VlessFlow string - CypherMethod string - ServerKey string - ServiceName string - Header json.RawMessage - NameServerConfig []*conf.NameServerConfig - EnableREALITY bool - REALITYConfig *REALITYConfig + AcceptProxyProtocol bool + Authority string + NodeType string // Must be V2ray, Trojan, and Shadowsocks + NodeID int + Port uint32 + SpeedLimit uint64 // Bps + AlterID uint16 + TransportProtocol string + FakeType string + Host string + Path string + EnableTLS bool + EnableSniffing bool + RouteOnly bool + EnableVless bool + VlessFlow string + CypherMethod string + ServerKey string + 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 { diff --git a/api/gov2panel/gov2panel.go b/api/gov2panel/gov2panel.go index 7322ff21..7c9d6d3c 100644 --- a/api/gov2panel/gov2panel.go +++ b/api/gov2panel/gov2panel.go @@ -177,7 +177,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { c.resp.Store(server) switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": nodeInfo, err = c.parseV2rayNodeResponse(server) case "Trojan": nodeInfo, err = c.parseTrojanNodeResponse(server) @@ -200,7 +200,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { path := "/api/server/user" switch c.NodeType { - case "V2ray", "Trojan", "Shadowsocks": + case "V2ray", "Trojan", "Shadowsocks", "Vmess", "Vless": break default: return nil, fmt.Errorf("unsupported node type: %s", c.NodeType) diff --git a/api/newV2board/v2board.go b/api/newV2board/v2board.go index 232cabf8..d3757bf4 100644 --- a/api/newV2board/v2board.go +++ b/api/newV2board/v2board.go @@ -184,7 +184,7 @@ func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { c.resp.Store(server) switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": nodeInfo, err = c.parseV2rayNodeResponse(server) case "Trojan": nodeInfo, err = c.parseTrojanNodeResponse(server) @@ -207,7 +207,7 @@ func (c *APIClient) GetUserList() (UserList *[]api.UserInfo, err error) { path := "/api/v1/server/UniProxy/user" switch c.NodeType { - case "V2ray", "Trojan", "Shadowsocks": + case "V2ray", "Trojan", "Shadowsocks", "Vmess", "Vless": break default: return nil, fmt.Errorf("unsupported node type: %s", c.NodeType) diff --git a/api/proxypanel/proxypanel.go b/api/proxypanel/proxypanel.go index dcb4a375..35706db5 100644 --- a/api/proxypanel/proxypanel.go +++ b/api/proxypanel/proxypanel.go @@ -145,7 +145,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) ( func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/node/%d", c.NodeID) case "Trojan": 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 { - case "V2ray": + case "V2ray", "Vmess", "Vless": nodeInfo, err = c.ParseV2rayNodeResponse(&response.Data) case "Trojan": 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) { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/userList/%d", c.NodeID) case "Trojan": 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) switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": userList, err = c.ParseV2rayUserListResponse(&response.Data) case "Trojan": 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) { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/nodeStatus/%d", c.NodeID) case "Trojan": 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 switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/nodeOnline/%d", c.NodeID) case "Trojan": 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 { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/userTraffic/%d", c.NodeID) case "Trojan": 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) { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/nodeRule/%d", c.NodeID) case "Trojan": 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 { var path string switch c.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": path = fmt.Sprintf("/api/v2ray/v1/trigger/%d", c.NodeID) case "Trojan": path = fmt.Sprintf("/api/trojan/v1/trigger/%d", c.NodeID) diff --git a/api/v2raysocks/v2raysocks.go b/api/v2raysocks/v2raysocks.go index 0ae98440..c91a5f05 100644 --- a/api/v2raysocks/v2raysocks.go +++ b/api/v2raysocks/v2raysocks.go @@ -151,7 +151,7 @@ func (c *APIClient) parseResponse(res *resty.Response, path string, err error) ( func (c *APIClient) GetNodeInfo() (nodeInfo *api.NodeInfo, err error) { var nodeType string switch c.NodeType { - case "V2ray", "Trojan", "Shadowsocks": + case "V2ray", "Vmess", "Vless", "Trojan", "Shadowsocks": nodeType = strings.ToLower(c.NodeType) default: 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 { - case "V2ray": + case "V2ray", "Vmess", "Vless": nodeInfo, err = c.ParseV2rayNodeResponse(response) case "Trojan": 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) { var nodeType string switch c.NodeType { - case "V2ray", "Trojan", "Shadowsocks": + case "V2ray", "Vmess", "Vless", "Trojan", "Shadowsocks": nodeType = strings.ToLower(c.NodeType) default: 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.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() - case "V2ray": + case "V2ray", "Vmess", "Vless": 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.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 { user.DeviceLimit = c.DeviceLimit } - + userList[i] = user } return &userList, nil diff --git a/release/config/config.yml.example b/release/config/config.yml.example index 5a02333c..7d870ad5 100644 --- a/release/config/config.yml.example +++ b/release/config/config.yml.example @@ -18,7 +18,7 @@ Nodes: ApiHost: "http://127.0.0.1:667" ApiKey: "123" 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 EnableVless: false # Enable Vless for V2ray Type VlessFlow: "xtls-rprx-vision" # Only support vless diff --git a/service/controller/controller.go b/service/controller/controller.go index 37def2f4..c1592abd 100644 --- a/service/controller/controller.go +++ b/service/controller/controller.go @@ -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) { users := make([]*protocol.User, 0) switch nodeInfo.NodeType { - case "V2ray": + case "V2ray", "Vmess", "Vless": if nodeInfo.EnableVless { users = c.buildVlessUser(userInfo) } else { diff --git a/service/controller/inboundbuilder.go b/service/controller/inboundbuilder.go index 4340f29c..bc1c8fe5 100644 --- a/service/controller/inboundbuilder.go +++ b/service/controller/inboundbuilder.go @@ -41,7 +41,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I // SniffingConfig sniffingConfig := &conf.SniffingConfig{ Enabled: true, - DestOverride: &conf.StringList{"http", "tls"}, + DestOverride: &conf.StringList{"http", "tls", "quic", "fakedns"}, } if config.DisableSniffing { sniffingConfig.Enabled = false @@ -57,8 +57,8 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I var proxySetting any // Build Protocol and Protocol setting switch nodeInfo.NodeType { - case "V2ray": - if nodeInfo.EnableVless { + case "V2ray", "Vmess", "Vless": + if nodeInfo.EnableVless || nodeInfo.NodeType == "Vless" { protocol = "vless" // Enable fallback if config.EnableFallback { @@ -164,6 +164,7 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I headers["Host"] = nodeInfo.Host wsSettings := &conf.WebSocketConfig{ AcceptProxyProtocol: config.EnableProxyProtocol, + Host: nodeInfo.Host, Path: nodeInfo.Path, Headers: headers, } @@ -171,17 +172,34 @@ func InboundBuilder(config *Config, nodeInfo *api.NodeInfo, tag string) (*core.I case "http": hosts := conf.StringList{nodeInfo.Host} httpSettings := &conf.HTTPConfig{ - Host: &hosts, - Path: nodeInfo.Path, + Host: &hosts, + Path: nodeInfo.Path, + Method: nodeInfo.Method, + Headers: nodeInfo.HttpHeaders, } streamSetting.HTTPSettings = httpSettings case "grpc": grpcSettings := &conf.GRPCConfig{ ServiceName: nodeInfo.ServiceName, + Authority: nodeInfo.Authority, } 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 // Build TLS and REALITY settings