diff --git a/api/panel/node.go b/api/panel/node.go index e731d42..d69a533 100644 --- a/api/panel/node.go +++ b/api/panel/node.go @@ -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 } diff --git a/common/builder/inbound.go b/common/builder/inbound.go index dc576f9..ad2b357 100644 --- a/common/builder/inbound.go +++ b/common/builder/inbound.go @@ -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{ { diff --git a/common/builder/user.go b/common/builder/user.go index a410a1d..4239626 100644 --- a/common/builder/user.go +++ b/common/builder/user.go @@ -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 { diff --git a/core/hy/user.go b/core/hy/user.go index 7aa2dda..a286dcc 100644 --- a/core/hy/user.go +++ b/core/hy/user.go @@ -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 } diff --git a/core/interface.go b/core/interface.go index 0af41fa..af29058 100644 --- a/core/interface.go +++ b/core/interface.go @@ -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 } diff --git a/core/selector.go b/core/selector.go index 03c25c7..997be8a 100644 --- a/core/selector.go +++ b/core/selector.go @@ -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") diff --git a/core/xray/distro/all/all.go b/core/xray/distro/all/all.go index 1a5f307..18057ee 100644 --- a/core/xray/distro/all/all.go +++ b/core/xray/distro/all/all.go @@ -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" diff --git a/core/xray/user.go b/core/xray/user.go index c636bc0..cea922b 100644 --- a/core/xray/user.go +++ b/core/xray/user.go @@ -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 } diff --git a/limiter/dynamic.go b/limiter/dynamic.go index 7e7d8c5..a74599e 100644 --- a/limiter/dynamic.go +++ b/limiter/dynamic.go @@ -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 } diff --git a/limiter/limiter.go b/limiter/limiter.go index ff45148..f8faf07 100644 --- a/limiter/limiter.go +++ b/limiter/limiter.go @@ -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 diff --git a/node/task.go b/node/task.go index 713c023..0cc05de 100644 --- a/node/task.go +++ b/node/task.go @@ -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) }