fix user tag

This commit is contained in:
yuzuki999 2023-06-19 10:31:42 +08:00
parent adf5c60c2a
commit 95a141ef59
9 changed files with 16 additions and 38 deletions

View File

@ -41,11 +41,6 @@ type ShadowsocksNodeRsp struct {
ServerKey string `json:"server_key"`
}
type TrojanNodeRsp struct {
Host string `json:"host"`
ServerName string `json:"server_name"`
}
type HysteriaNodeRsp struct {
UpMbps int `json:"up_mbps"`
DownMbps int `json:"down_mbps"`
@ -131,11 +126,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
node.ServerKey = rsp.ServerKey
node.Cipher = rsp.Cipher
case "trojan":
rsp := TrojanNodeRsp{}
err = json.Unmarshal(r.Body(), &rsp)
if err != nil {
return nil, fmt.Errorf("decode v2ray params error: %s", err)
}
case "hysteria":
rsp := HysteriaNodeRsp{}
err = json.Unmarshal(r.Body(), &rsp)

View File

@ -93,7 +93,7 @@ func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey
}
return &protocol.User{
Level: 0,
Email: tag,
Email: BuildUserTag(tag, userInfo.Uuid),
Account: serial.ToTypedMessage(ssAccount),
}
} else {

View File

@ -3,6 +3,7 @@ package hy
import (
"encoding/base64"
"errors"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/core"
)
@ -30,15 +31,15 @@ func (h *Hy) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
return
}
func (h *Hy) DelUsers(users []string, tag string) error {
func (h *Hy) DelUsers(users []panel.UserInfo, tag string) error {
v, e := h.servers.Load(tag)
if !e {
return errors.New("the node is not have")
}
s := v.(*Server)
for i := range users {
s.users.Delete(users[i])
s.counter.Delete(users[i])
s.users.Delete(users[i].Uuid)
s.counter.Delete(base64.StdEncoding.EncodeToString([]byte(users[i].Uuid)))
}
return nil
}

View File

@ -18,6 +18,6 @@ type Core interface {
DelNode(tag string) error
AddUsers(p *AddUsersParams) (added int, err error)
GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
DelUsers(users []string, tag string) error
DelUsers(users []panel.UserInfo, tag string) error
Protocols() []string
}

View File

@ -81,7 +81,7 @@ func (s *Selector) GetUserTraffic(tag, uuid string, reset bool) (up int64, down
return s.cores[t.(int)].GetUserTraffic(tag, uuid, reset)
}
func (s *Selector) DelUsers(users []string, tag string) error {
func (s *Selector) DelUsers(users []panel.UserInfo, tag string) error {
t, e := s.nodes.Load(tag)
if !e {
return errors.New("the node is not have")

View File

@ -3,6 +3,7 @@ package xray
import (
"context"
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/common/builder"
vCore "github.com/Yuzuki616/V2bX/core"
"github.com/xtls/xray-core/common/protocol"
@ -25,13 +26,13 @@ func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
return userManager, nil
}
func (c *Core) DelUsers(users []string, tag string) error {
func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
userManager, err := c.GetUserManager(tag)
if err != nil {
return fmt.Errorf("get user manager error: %s", err)
}
for _, email := range users {
err = userManager.RemoveUser(context.Background(), email)
for i := range users {
err = userManager.RemoveUser(context.Background(), builder.BuildUserTag(tag, users[i].Uuid))
if err != nil {
return err
}

View File

@ -1,8 +1,8 @@
package limiter
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/common/builder"
"time"
)
@ -11,7 +11,7 @@ func (l *Limiter) AddDynamicSpeedLimit(tag string, userInfo *panel.UserInfo, lim
DynamicSpeedLimit: limitNum,
ExpireTime: time.Now().Add(time.Duration(expire) * time.Second).Unix(),
}
l.UserLimitInfo.Store(fmt.Sprintf("%s|%s|%d", tag, userInfo.Uuid, userInfo.Id), userLimit)
l.UserLimitInfo.Store(builder.BuildUserTag(tag, userInfo.Uuid), userLimit)
return nil
}

View File

@ -85,10 +85,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
return fmt.Errorf("get limit error: %s", err)
}
for i := range deleted {
l.UserLimitInfo.Delete(fmt.Sprintf("%s|%s|%d",
tag,
deleted[i].Uuid,
deleted[i].Id))
l.UserLimitInfo.Delete(builder.BuildUserTag(tag, deleted[i].Uuid))
}
for i := range added {
if added[i].SpeedLimit != 0 {
@ -97,10 +94,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
SpeedLimit: added[i].SpeedLimit,
ExpireTime: 0,
}
l.UserLimitInfo.Store(fmt.Sprintf("%s|%s|%d",
tag,
added[i].Uuid,
added[i].Id), userLimit)
l.UserLimitInfo.Store(builder.BuildUserTag(tag, added[i].Uuid), userLimit)
}
}
return nil

View File

@ -1,7 +1,6 @@
package node
import (
"fmt"
"github.com/Yuzuki616/V2bX/common/task"
vCore "github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/limiter"
@ -116,14 +115,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
deleted, added := compareUserList(c.userList, newUserInfo)
if len(deleted) > 0 {
// have deleted users
deletedEmail := make([]string, len(deleted))
for i := range deleted {
deletedEmail[i] = fmt.Sprintf("%s|%s|%d",
c.Tag,
(deleted)[i].Uuid,
(deleted)[i].Id)
}
err = c.server.DelUsers(deletedEmail, c.Tag)
err = c.server.DelUsers(deleted, c.Tag)
if err != nil {
log.Printf("[%s] Del users error: %s", c.Tag, err)
}