测试:尝试增加hysteria2协议,尝试增加设备数限制功能

This commit is contained in:
wyx2685
2023-11-18 07:05:28 +09:00
parent f928b4f8f3
commit cf8016f405
18 changed files with 380 additions and 323 deletions

View File

@@ -2,6 +2,7 @@ package panel
import (
"fmt"
"github.com/goccy/go-json"
)
@@ -11,9 +12,11 @@ type OnlineUser struct {
}
type UserInfo struct {
Id int `json:"id"`
Uuid string `json:"uuid"`
SpeedLimit int `json:"speed_limit"`
Id int `json:"id"`
Uuid string `json:"uuid"`
SpeedLimit int `json:"speed_limit"`
DeviceLimit int `json:"device_limit"`
AliveIp int `json:"alive_ip"`
}
type UserListBody struct {
@@ -31,7 +34,7 @@ func (c *Client) GetUserList() (UserList []UserInfo, err error) {
if err != nil {
return nil, err
}
err = c.checkResponse(r, path, err)
if r.StatusCode() == 304 {
return nil, nil
}
@@ -41,7 +44,30 @@ func (c *Client) GetUserList() (UserList []UserInfo, err error) {
return nil, fmt.Errorf("unmarshal userlist error: %s", err)
}
c.userEtag = r.Header().Get("ETag")
return userList.Users, nil
var userinfos []UserInfo
var localDeviceLimit int = 0
for _, user := range userList.Users {
// If there is still device available, add the user
if user.DeviceLimit > 0 && user.AliveIp > 0 {
lastOnline := 0
if v, ok := c.LastReportOnline[user.Id]; ok {
lastOnline = v
}
// If there are any available device.
localDeviceLimit = user.DeviceLimit - user.AliveIp + lastOnline
if localDeviceLimit > 0 {
} else if lastOnline > 0 {
} else {
continue
}
}
userinfos = append(userinfos, user)
}
return userinfos, nil
}
type UserTraffic struct {
@@ -67,3 +93,19 @@ func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error {
}
return nil
}
func (c *Client) ReportNodeOnlineUsers(data *map[int][]string, reportOnline *map[int]int) error {
c.LastReportOnline = *reportOnline
const path = "/api/v1/server/UniProxy/alive"
r, err := c.client.R().
SetBody(data).
ForceContentType("application/json").
Post(path)
err = c.checkResponse(r, path, err)
if err != nil {
return nil
}
return nil
}