mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
@@ -41,11 +41,6 @@ type ShadowsocksNodeRsp struct {
|
|||||||
ServerKey string `json:"server_key"`
|
ServerKey string `json:"server_key"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrojanNodeRsp struct {
|
|
||||||
Host string `json:"host"`
|
|
||||||
ServerName string `json:"server_name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type HysteriaNodeRsp struct {
|
type HysteriaNodeRsp struct {
|
||||||
UpMbps int `json:"up_mbps"`
|
UpMbps int `json:"up_mbps"`
|
||||||
DownMbps int `json:"down_mbps"`
|
DownMbps int `json:"down_mbps"`
|
||||||
@@ -131,11 +126,6 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
node.ServerKey = rsp.ServerKey
|
node.ServerKey = rsp.ServerKey
|
||||||
node.Cipher = rsp.Cipher
|
node.Cipher = rsp.Cipher
|
||||||
case "trojan":
|
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":
|
case "hysteria":
|
||||||
rsp := HysteriaNodeRsp{}
|
rsp := HysteriaNodeRsp{}
|
||||||
err = json.Unmarshal(r.Body(), &rsp)
|
err = json.Unmarshal(r.Body(), &rsp)
|
||||||
@@ -146,7 +136,7 @@ func (c *Client) GetNodeInfo() (node *NodeInfo, err error) {
|
|||||||
node.UpMbps = rsp.UpMbps
|
node.UpMbps = rsp.UpMbps
|
||||||
node.HyObfs = rsp.Obfs
|
node.HyObfs = rsp.Obfs
|
||||||
}
|
}
|
||||||
c.etag = r.Header().Get("Etag")
|
c.etag = r.Header().Get("ETag")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ func BuildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag s
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Normal tls
|
// Normal tls
|
||||||
|
in.StreamSetting.Security = "tls"
|
||||||
in.StreamSetting.TLSSettings = &coreConf.TLSConfig{
|
in.StreamSetting.TLSSettings = &coreConf.TLSConfig{
|
||||||
Certs: []*coreConf.TLSCertConfig{
|
Certs: []*coreConf.TLSCertConfig{
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ func BuildSSUser(tag string, userInfo *panel.UserInfo, cypher string, serverKey
|
|||||||
}
|
}
|
||||||
return &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: tag,
|
Email: BuildUserTag(tag, userInfo.Uuid),
|
||||||
Account: serial.ToTypedMessage(ssAccount),
|
Account: serial.ToTypedMessage(ssAccount),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package hy
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/core"
|
"github.com/Yuzuki616/V2bX/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,15 +31,15 @@ func (h *Hy) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
|
|||||||
return
|
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)
|
v, e := h.servers.Load(tag)
|
||||||
if !e {
|
if !e {
|
||||||
return errors.New("the node is not have")
|
return errors.New("the node is not have")
|
||||||
}
|
}
|
||||||
s := v.(*Server)
|
s := v.(*Server)
|
||||||
for i := range users {
|
for i := range users {
|
||||||
s.users.Delete(users[i])
|
s.users.Delete(users[i].Uuid)
|
||||||
s.counter.Delete(users[i])
|
s.counter.Delete(base64.StdEncoding.EncodeToString([]byte(users[i].Uuid)))
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ type Core interface {
|
|||||||
DelNode(tag string) error
|
DelNode(tag string) error
|
||||||
AddUsers(p *AddUsersParams) (added int, err error)
|
AddUsers(p *AddUsersParams) (added int, err error)
|
||||||
GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64)
|
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
|
Protocols() []string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
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)
|
t, e := s.nodes.Load(tag)
|
||||||
if !e {
|
if !e {
|
||||||
return errors.New("the node is not have")
|
return errors.New("the node is not have")
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import (
|
|||||||
_ "github.com/xtls/xray-core/app/dns"
|
_ "github.com/xtls/xray-core/app/dns"
|
||||||
_ "github.com/xtls/xray-core/app/dns/fakedns"
|
_ "github.com/xtls/xray-core/app/dns/fakedns"
|
||||||
_ "github.com/xtls/xray-core/app/log"
|
_ "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/policy"
|
||||||
_ "github.com/xtls/xray-core/app/reverse"
|
_ "github.com/xtls/xray-core/app/reverse"
|
||||||
_ "github.com/xtls/xray-core/app/router"
|
_ "github.com/xtls/xray-core/app/router"
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package xray
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/common/builder"
|
"github.com/Yuzuki616/V2bX/common/builder"
|
||||||
vCore "github.com/Yuzuki616/V2bX/core"
|
vCore "github.com/Yuzuki616/V2bX/core"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
@@ -25,16 +26,22 @@ func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
|
|||||||
return userManager, nil
|
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)
|
userManager, err := c.GetUserManager(tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("get user manager error: %s", err)
|
return fmt.Errorf("get user manager error: %s", err)
|
||||||
}
|
}
|
||||||
for _, email := range users {
|
var up, down, user string
|
||||||
err = userManager.RemoveUser(context.Background(), email)
|
for i := range users {
|
||||||
|
user = builder.BuildUserTag(tag, users[i].Uuid)
|
||||||
|
err = userManager.RemoveUser(context.Background(), user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
up = "user>>>" + user + ">>>traffic>>>uplink"
|
||||||
|
down = "user>>>" + user + ">>>traffic>>>downlink"
|
||||||
|
c.shm.UnregisterCounter(up)
|
||||||
|
c.shm.UnregisterCounter(down)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package limiter
|
package limiter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
|
"github.com/Yuzuki616/V2bX/common/builder"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ func (l *Limiter) AddDynamicSpeedLimit(tag string, userInfo *panel.UserInfo, lim
|
|||||||
DynamicSpeedLimit: limitNum,
|
DynamicSpeedLimit: limitNum,
|
||||||
ExpireTime: time.Now().Add(time.Duration(expire) * time.Second).Unix(),
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -85,10 +85,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
|
|||||||
return fmt.Errorf("get limit error: %s", err)
|
return fmt.Errorf("get limit error: %s", err)
|
||||||
}
|
}
|
||||||
for i := range deleted {
|
for i := range deleted {
|
||||||
l.UserLimitInfo.Delete(fmt.Sprintf("%s|%s|%d",
|
l.UserLimitInfo.Delete(builder.BuildUserTag(tag, deleted[i].Uuid))
|
||||||
tag,
|
|
||||||
deleted[i].Uuid,
|
|
||||||
deleted[i].Id))
|
|
||||||
}
|
}
|
||||||
for i := range added {
|
for i := range added {
|
||||||
if added[i].SpeedLimit != 0 {
|
if added[i].SpeedLimit != 0 {
|
||||||
@@ -97,10 +94,7 @@ func UpdateLimiter(tag string, added []panel.UserInfo, deleted []panel.UserInfo)
|
|||||||
SpeedLimit: added[i].SpeedLimit,
|
SpeedLimit: added[i].SpeedLimit,
|
||||||
ExpireTime: 0,
|
ExpireTime: 0,
|
||||||
}
|
}
|
||||||
l.UserLimitInfo.Store(fmt.Sprintf("%s|%s|%d",
|
l.UserLimitInfo.Store(builder.BuildUserTag(tag, added[i].Uuid), userLimit)
|
||||||
tag,
|
|
||||||
added[i].Uuid,
|
|
||||||
added[i].Id), userLimit)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
12
node/task.go
12
node/task.go
@@ -1,7 +1,6 @@
|
|||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/Yuzuki616/V2bX/common/task"
|
"github.com/Yuzuki616/V2bX/common/task"
|
||||||
vCore "github.com/Yuzuki616/V2bX/core"
|
vCore "github.com/Yuzuki616/V2bX/core"
|
||||||
"github.com/Yuzuki616/V2bX/limiter"
|
"github.com/Yuzuki616/V2bX/limiter"
|
||||||
@@ -56,6 +55,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
if newNodeInfo != nil {
|
if newNodeInfo != nil {
|
||||||
// nodeInfo changed
|
// nodeInfo changed
|
||||||
// Remove old tag
|
// Remove old tag
|
||||||
|
log.Printf("[%s] Node changed, reload...", c.Tag)
|
||||||
err = c.server.DelNode(c.Tag)
|
err = c.server.DelNode(c.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] Del node error: %s", c.Tag, err)
|
log.Printf("[%s] Del node error: %s", c.Tag, err)
|
||||||
@@ -108,6 +108,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
}
|
}
|
||||||
c.nodeInfo = newNodeInfo
|
c.nodeInfo = newNodeInfo
|
||||||
c.userList = newUserInfo
|
c.userList = newUserInfo
|
||||||
|
log.Printf("[%s] Added %d new users", c.Tag, len(newUserInfo))
|
||||||
// exit
|
// exit
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -116,14 +117,7 @@ func (c *Controller) nodeInfoMonitor() (err error) {
|
|||||||
deleted, added := compareUserList(c.userList, newUserInfo)
|
deleted, added := compareUserList(c.userList, newUserInfo)
|
||||||
if len(deleted) > 0 {
|
if len(deleted) > 0 {
|
||||||
// have deleted users
|
// have deleted users
|
||||||
deletedEmail := make([]string, len(deleted))
|
err = c.server.DelUsers(deleted, c.Tag)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[%s] Del users error: %s", c.Tag, err)
|
log.Printf("[%s] Del users error: %s", c.Tag, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user