Skip to content

Commit

Permalink
add quic support and fixed some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxin239 committed Jun 9, 2024
1 parent 9261a60 commit 175e46d
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 45 deletions.
60 changes: 41 additions & 19 deletions api/apimodel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions api/gov2panel/gov2panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions api/newV2board/v2board.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions api/proxypanel/proxypanel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions api/v2raysocks/v2raysocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion release/config/config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion service/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 24 additions & 6 deletions service/controller/inboundbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -164,24 +164,42 @@ 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,
}
streamSetting.WSSettings = wsSettings
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
Expand Down

0 comments on commit 175e46d

Please sign in to comment.