add dynamic speed limit

fix old user limit info not clear
fix some wrong names
This commit is contained in:
yuzuki999
2022-09-07 23:02:02 +08:00
parent 52134c6e4e
commit 5fd09079e3
10 changed files with 211 additions and 130 deletions

View File

@@ -1,78 +0,0 @@
// Package api contains all the api used by XrayR
// To implement an api , one needs to implement the interface below.
package panel
import (
"github.com/Yuzuki616/V2bX/conf"
"github.com/go-resty/resty/v2"
"log"
"strconv"
"sync"
"time"
)
// 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
NodeID int
Key string
NodeType string
//EnableSS2022 bool
EnableVless bool
EnableXTLS bool
SpeedLimit float64
DeviceLimit int
LocalRuleList []DetectRule
RemoteRuleCache *[]Rule
access sync.Mutex
NodeInfoRspMd5 [16]byte
NodeRuleRspMd5 [16]byte
}
func New(apiConfig *conf.ApiConfig) Panel {
client := resty.New()
client.SetRetryCount(3)
if apiConfig.Timeout > 0 {
client.SetTimeout(time.Duration(apiConfig.Timeout) * time.Second)
} else {
client.SetTimeout(5 * time.Second)
}
client.OnError(func(req *resty.Request, err error) {
if v, ok := err.(*resty.ResponseError); ok {
// v.Response contains the last response from the server
// v.Err contains the original error
log.Print(v.Err)
}
})
client.SetBaseURL(apiConfig.APIHost)
// Create Key for each requests
client.SetQueryParams(map[string]string{
"node_id": strconv.Itoa(apiConfig.NodeID),
"token": apiConfig.Key,
})
// Read local rule list
localRuleList := readLocalRuleList(apiConfig.RuleListPath)
return &Client{
client: client,
NodeID: apiConfig.NodeID,
Key: apiConfig.Key,
APIHost: apiConfig.APIHost,
NodeType: apiConfig.NodeType,
//EnableSS2022: apiConfig.EnableSS2022,
EnableVless: apiConfig.EnableVless,
EnableXTLS: apiConfig.EnableXTLS,
SpeedLimit: apiConfig.SpeedLimit,
DeviceLimit: apiConfig.DeviceLimit,
LocalRuleList: localRuleList,
}
}

10
api/panel/interface.go Normal file
View File

@@ -0,0 +1,10 @@
package panel
type Panel interface {
GetNodeInfo() (nodeInfo *NodeInfo, err error)
GetUserList() (userList []UserInfo, err error)
ReportUserTraffic(userTraffic []UserTraffic) (err error)
Describe() ClientInfo
GetNodeRule() (ruleList []DetectRule, protocolList []string, err error)
Debug()
}

View File

@@ -1,10 +1,75 @@
package panel
type Panel interface {
GetNodeInfo() (nodeInfo *NodeInfo, err error)
GetUserList() (userList []UserInfo, err error)
ReportUserTraffic(userTraffic []UserTraffic) (err error)
Describe() ClientInfo
GetNodeRule() (ruleList []DetectRule, protocolList []string, err error)
Debug()
import (
"github.com/Yuzuki616/V2bX/conf"
"github.com/go-resty/resty/v2"
"log"
"strconv"
"sync"
"time"
)
// 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
NodeID int
Key string
NodeType string
//EnableSS2022 bool
EnableVless bool
EnableXTLS bool
SpeedLimit float64
DeviceLimit int
LocalRuleList []DetectRule
RemoteRuleCache *[]Rule
access sync.Mutex
NodeInfoRspMd5 [16]byte
NodeRuleRspMd5 [16]byte
}
func New(apiConfig *conf.ApiConfig) Panel {
client := resty.New()
client.SetRetryCount(3)
if apiConfig.Timeout > 0 {
client.SetTimeout(time.Duration(apiConfig.Timeout) * time.Second)
} else {
client.SetTimeout(5 * time.Second)
}
client.OnError(func(req *resty.Request, err error) {
if v, ok := err.(*resty.ResponseError); ok {
// v.Response contains the last response from the server
// v.Err contains the original error
log.Print(v.Err)
}
})
client.SetBaseURL(apiConfig.APIHost)
// Create Key for each requests
client.SetQueryParams(map[string]string{
"node_id": strconv.Itoa(apiConfig.NodeID),
"token": apiConfig.Key,
})
// Read local rule list
localRuleList := readLocalRuleList(apiConfig.RuleListPath)
return &Client{
client: client,
NodeID: apiConfig.NodeID,
Key: apiConfig.Key,
APIHost: apiConfig.APIHost,
NodeType: apiConfig.NodeType,
//EnableSS2022: apiConfig.EnableSS2022,
EnableVless: apiConfig.EnableVless,
EnableXTLS: apiConfig.EnableXTLS,
SpeedLimit: apiConfig.SpeedLimit,
DeviceLimit: apiConfig.DeviceLimit,
LocalRuleList: localRuleList,
}
}

View File

@@ -23,6 +23,7 @@ type UserInfo struct {
/*DeviceLimit int `json:"device_limit"`
SpeedLimit uint64 `json:"speed_limit"`*/
UID int `json:"id"`
Traffic int64 `json:"-"`
Port int `json:"port"`
Cipher string `json:"cipher"`
Secret string `json:"secret"`