Merge pull request #82 from Yuzuki616/dev

Dev
This commit is contained in:
Yuzuki 2023-06-20 17:10:39 +08:00 committed by GitHub
commit b941700a5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 27 additions and 40 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)
@ -146,7 +136,7 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
node.UpMbps = rsp.UpMbps
node.HyObfs = rsp.Obfs
}
c.etag = r.Header().Get("Etag")
c.etag = r.Header().Get("ETag")
return
}

View File

@ -89,6 +89,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
}
default:
// Normal tls
in.StreamSetting.Security = "tls"
in.StreamSetting.TLSSettings = &coreConf.TLSConfig{
Certs: []*coreConf.TLSCertConfig{
{

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

@ -21,7 +21,7 @@ import (
_ "github.com/xtls/xray-core/app/dns"
_ "github.com/xtls/xray-core/app/dns/fakedns"
_ "github.com/xtls/xray-core/app/log"
_ "github.com/xtls/xray-core/app/metrics"
//_ "github.com/xtls/xray-core/app/metrics"
_ "github.com/xtls/xray-core/app/policy"
_ "github.com/xtls/xray-core/app/reverse"
_ "github.com/xtls/xray-core/app/router"

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,16 +26,22 @@ 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)
var up, down, user string
for i := range users {
user = builder.BuildUserTag(tag, users[i].Uuid)
err = userManager.RemoveUser(context.Background(), user)
if err != nil {
return err
}
up = "user>>>" + user + ">>>traffic>>>uplink"
down = "user>>>" + user + ">>>traffic>>>downlink"
c.shm.UnregisterCounter(up)
c.shm.UnregisterCounter(down)
}
return nil
}

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"
@ -56,6 +55,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
if newNodeInfo != nil {
// nodeInfo changed
// Remove old tag
log.Printf("[%s] Node changed, reload...", c.Tag)
err = c.server.DelNode(c.Tag)
if err != nil {
log.Printf("[%s] Del node error: %s", c.Tag, err)
@ -108,6 +108,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
}
c.nodeInfo = newNodeInfo
c.userList = newUserInfo
log.Printf("[%s] Added %d new users", c.Tag, len(newUserInfo))
// exit
return nil
}
@ -116,14 +117,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)
}