support xtls-rprx-vision, support reality

This commit is contained in:
yuzuki999
2023-05-22 10:36:10 +08:00
parent 0ebc45e2d2
commit 40edaedb22
13 changed files with 112 additions and 223 deletions

View File

@@ -10,18 +10,19 @@ import (
)
type NodeInfo struct {
Host string `json:"host"`
ServerPort int `json:"server_port"`
ServerName string `json:"server_name"`
Network string `json:"network"`
NetworkSettings json.RawMessage `json:"networkSettings"`
Cipher string `json:"cipher"`
ServerKey string `json:"server_key"`
Tls int `json:"tls"`
Routes []Route `json:"routes"`
BaseConfig *BaseConfig `json:"base_config"`
Rules []DestinationRule `json:"-"`
localNodeConfig `json:"-"`
NodeId int `json:"-"`
NodeType string `json:"-"`
Rules []*regexp.Regexp `json:"-"`
Host string `json:"host"`
ServerPort int `json:"server_port"`
ServerName string `json:"server_name"`
Network string `json:"network"`
NetworkSettings json.RawMessage `json:"networkSettings"`
Cipher string `json:"cipher"`
ServerKey string `json:"server_key"`
Tls int `json:"tls"`
Routes []Route `json:"routes"`
BaseConfig *BaseConfig `json:"base_config"`
}
type Route struct {
Id int `json:"id"`
@@ -33,14 +34,6 @@ type BaseConfig struct {
PushInterval any `json:"push_interval"`
PullInterval any `json:"pull_interval"`
}
type DestinationRule struct {
ID int
Pattern *regexp.Regexp
}
type localNodeConfig struct {
NodeId int
NodeType string
}
func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
const path = "/api/v1/server/UniProxy/config"
@@ -66,10 +59,7 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
matchs = nodeInfo.Routes[i].Match.([]string)
}
for _, v := range matchs {
nodeInfo.Rules = append(nodeInfo.Rules, DestinationRule{
ID: nodeInfo.Routes[i].Id,
Pattern: regexp.MustCompile(v),
})
nodeInfo.Rules = append(nodeInfo.Rules, regexp.MustCompile(v))
}
}
}

View File

@@ -15,20 +15,13 @@ import (
// Panel is the interface for different panel's api.
type ClientInfo struct {
APIHost string
NodeID int
Key string
NodeType string
}
type Client struct {
client *resty.Client
APIHost string
Key string
NodeType string
NodeId int
LocalRuleList []DestinationRule
LocalRuleList []*regexp.Regexp
etag string
}
@@ -74,8 +67,8 @@ func New(c *conf.ApiConfig) (*Client, error) {
}
// readLocalRuleList reads the local rule list file
func readLocalRuleList(path string) (LocalRuleList []DestinationRule) {
LocalRuleList = make([]DestinationRule, 0)
func readLocalRuleList(path string) (LocalRuleList []*regexp.Regexp) {
LocalRuleList = make([]*regexp.Regexp, 0)
if path != "" {
// open the file
file, err := os.Open(path)
@@ -87,10 +80,7 @@ func readLocalRuleList(path string) (LocalRuleList []DestinationRule) {
fileScanner := bufio.NewScanner(file)
// read line by line
for fileScanner.Scan() {
LocalRuleList = append(LocalRuleList, DestinationRule{
ID: -1,
Pattern: regexp.MustCompile(fileScanner.Text()),
})
LocalRuleList = append(LocalRuleList, regexp.MustCompile(fileScanner.Text()))
}
// handle first encountered error while reading
if err := fileScanner.Err(); err != nil {

View File

@@ -6,11 +6,6 @@ import (
path2 "path"
)
// Describe return a description of the client
func (c *Client) Describe() ClientInfo {
return ClientInfo{APIHost: c.APIHost, NodeID: c.NodeId, Key: c.Key, NodeType: c.NodeType}
}
// Debug set the client debug for client
func (c *Client) Debug() {
c.client.SetDebug(true)