change project structure, performance optimization

This commit is contained in:
yuzuki999 2022-08-12 18:02:06 +08:00
parent 4bd389aa05
commit ba1e088afb
51 changed files with 181 additions and 190 deletions

5
.gitignore vendored
View File

@ -6,11 +6,10 @@ example/mytest
example/access.logo example/access.logo
example/error.log example/error.log
api/chooseparser.go.bak api/chooseparser.go.bak
common/Inboundbuilder/.lego/ app/Inboundbuilder/.lego/
common/legocmd/.lego/ app/legocmd/.lego/
.vscode/launch.json .vscode/launch.json
example/.lego example/.lego
example/cert example/cert
example/config.yml
./vscode ./vscode
.idea/* .idea/*

View File

@ -2,9 +2,9 @@ package api
type API interface { type API interface {
GetNodeInfo() (nodeInfo *NodeInfo, err error) GetNodeInfo() (nodeInfo *NodeInfo, err error)
GetUserList() (userList *[]UserInfo, err error) GetUserList() (userList []UserInfo, err error)
ReportUserTraffic(userTraffic *[]UserTraffic) (err error) ReportUserTraffic(userTraffic []UserTraffic) (err error)
Describe() ClientInfo Describe() ClientInfo
GetNodeRule() (ruleList *[]DetectRule, protocolList *[]string, err error) GetNodeRule() (ruleList []DetectRule, protocolList []string, err error)
Debug() Debug()
} }

View File

@ -160,10 +160,10 @@ func (c *Client) GetNodeInfo() (nodeInfo *NodeInfo, err error) {
return nodeInfo, nil return nodeInfo, nil
} }
func (c *Client) GetNodeRule() (*[]DetectRule, *[]string, error) { func (c *Client) GetNodeRule() ([]DetectRule, []string, error) {
ruleList := c.LocalRuleList ruleList := c.LocalRuleList
if c.NodeType != "V2ray" || c.RemoteRuleCache == nil { if c.NodeType != "V2ray" || c.RemoteRuleCache == nil {
return &ruleList, nil, nil return ruleList, nil, nil
} }
// V2board only support the rule for v2ray // V2board only support the rule for v2ray
// fix: reuse config response // fix: reuse config response
@ -185,7 +185,7 @@ func (c *Client) GetNodeRule() (*[]DetectRule, *[]string, error) {
} }
} }
c.RemoteRuleCache = nil c.RemoteRuleCache = nil
return &ruleList, &protocolList, nil return ruleList, protocolList, nil
} }
// ParseTrojanNodeResponse parse the response for the given nodeinfor format // ParseTrojanNodeResponse parse the response for the given nodeinfor format
@ -211,9 +211,9 @@ func (c *Client) ParseSSNodeResponse() (*NodeInfo, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
if len(*userInfo) > 0 { if len(userInfo) > 0 {
port = (*userInfo)[0].Port port = userInfo[0].Port
method = (*userInfo)[0].Cipher method = userInfo[0].Cipher
} else { } else {
return nil, fmt.Errorf("shadowsocks node need a active user") return nil, fmt.Errorf("shadowsocks node need a active user")
} }

View File

@ -45,7 +45,7 @@ type UserListBody struct {
} }
// GetUserList will pull user form sspanel // GetUserList will pull user form sspanel
func (c *Client) GetUserList() (UserList *[]UserInfo, err error) { func (c *Client) GetUserList() (UserList []UserInfo, err error) {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray":
@ -69,7 +69,7 @@ func (c *Client) GetUserList() (UserList *[]UserInfo, err error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("unmarshal userlist error: %s", err) return nil, fmt.Errorf("unmarshal userlist error: %s", err)
} }
return &userList.Data, nil return userList.Data, nil
} }
type UserTraffic struct { type UserTraffic struct {
@ -79,7 +79,7 @@ type UserTraffic struct {
} }
// ReportUserTraffic reports the user traffic // ReportUserTraffic reports the user traffic
func (c *Client) ReportUserTraffic(userTraffic *[]UserTraffic) error { func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error {
var path string var path string
switch c.NodeType { switch c.NodeType {
case "V2ray": case "V2ray":
@ -90,8 +90,8 @@ func (c *Client) ReportUserTraffic(userTraffic *[]UserTraffic) error {
path = "/api/v1/server/ShadowsocksTidalab/submit" path = "/api/v1/server/ShadowsocksTidalab/submit"
} }
data := make([]UserTraffic, len(*userTraffic)) data := make([]UserTraffic, len(userTraffic))
for i, traffic := range *userTraffic { for i, traffic := range userTraffic {
data[i] = UserTraffic{ data[i] = UserTraffic{
UID: traffic.UID, UID: traffic.UID,
Upload: traffic.Upload, Upload: traffic.Upload,

View File

@ -1,2 +1,2 @@
// Package app contains the third-party app used to replace the default app in xray-core // Package app contains feature implementations of XrayR.
package app package app

View File

@ -13,7 +13,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -11,7 +11,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
"github.com/urfave/cli" "github.com/urfave/cli"

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View File

@ -5,7 +5,7 @@ import (
"crypto/x509" "crypto/x509"
"time" "time"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"

View File

@ -1,7 +1,7 @@
package cmd package cmd
import ( import (
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View File

@ -6,7 +6,7 @@ import (
"os" "os"
"strings" "strings"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certificate" "github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -9,7 +9,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/lego" "github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration" "github.com/go-acme/lego/v4/registration"

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/Yuzuki616/V2bX/common/legoCmd/log" "github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/challenge" "github.com/go-acme/lego/v4/challenge"
"github.com/go-acme/lego/v4/challenge/dns01" "github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/challenge/http01" "github.com/go-acme/lego/v4/challenge/http01"

View File

@ -11,7 +11,7 @@ import (
"runtime" "runtime"
"strings" "strings"
"github.com/Yuzuki616/V2bX/common/legoCmd/cmd" "github.com/Yuzuki616/V2bX/app/legoCmd/cmd"
"github.com/urfave/cli" "github.com/urfave/cli"
) )

View File

@ -3,7 +3,7 @@ package legoCmd_test
import ( import (
"testing" "testing"
"github.com/Yuzuki616/V2bX/common/legoCmd" "github.com/Yuzuki616/V2bX/app/legoCmd"
) )
func TestLegoClient(t *testing.T) { func TestLegoClient(t *testing.T) {

View File

@ -34,7 +34,7 @@ func New() *Limiter {
} }
} }
func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList *[]api.UserInfo) error { func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList []api.UserInfo) error {
inboundInfo := &InboundInfo{ inboundInfo := &InboundInfo{
Tag: tag, Tag: tag,
NodeSpeedLimit: nodeInfo.SpeedLimit, NodeSpeedLimit: nodeInfo.SpeedLimit,
@ -42,37 +42,38 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList
UserOnlineIP: new(sync.Map), UserOnlineIP: new(sync.Map),
} }
userMap := new(sync.Map) userMap := new(sync.Map)
for i := range *userList { for i := range userList {
/*if (*userList)[i].SpeedLimit == 0 { /*if (*userList)[i].SpeedLimit == 0 {
(*userList)[i].SpeedLimit = nodeInfo.SpeedLimit (*userList)[i].SpeedLimit = nodeInfo.SpeedLimit
} }
if (*userList)[i].DeviceLimit == 0 { if (*userList)[i].DeviceLimit == 0 {
(*userList)[i].DeviceLimit = nodeInfo.DeviceLimit (*userList)[i].DeviceLimit = nodeInfo.DeviceLimit
}*/ }*/
userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (*userList)[i].V2rayUser.Email, (*userList)[i].UID), UserInfo{ userMap.Store(fmt.Sprintf("%s|%s|%d", tag, (userList)[i].V2rayUser.Email, (userList)[i].UID),
UID: (*userList)[i].UID, UserInfo{
SpeedLimit: nodeInfo.SpeedLimit, UID: (userList)[i].UID,
DeviceLimit: nodeInfo.DeviceLimit, SpeedLimit: nodeInfo.SpeedLimit,
}) DeviceLimit: nodeInfo.DeviceLimit,
})
} }
inboundInfo.UserInfo = userMap inboundInfo.UserInfo = userMap
l.InboundInfo.Store(tag, inboundInfo) // Replace the old inbound info l.InboundInfo.Store(tag, inboundInfo) // Replace the old inbound info
return nil return nil
} }
func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList *[]api.UserInfo) error { func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList []api.UserInfo) error {
if value, ok := l.InboundInfo.Load(tag); ok { if value, ok := l.InboundInfo.Load(tag); ok {
inboundInfo := value.(*InboundInfo) inboundInfo := value.(*InboundInfo)
// Update User info // Update User info
for i := range *updatedUserList { for i := range updatedUserList {
inboundInfo.UserInfo.Store(fmt.Sprintf("%s|%s|%d", tag, inboundInfo.UserInfo.Store(fmt.Sprintf("%s|%s|%d", tag,
(*updatedUserList)[i].V2rayUser.Email, (*updatedUserList)[i].UID), UserInfo{ (updatedUserList)[i].V2rayUser.Email, (updatedUserList)[i].UID), UserInfo{
UID: (*updatedUserList)[i].UID, UID: (updatedUserList)[i].UID,
SpeedLimit: nodeInfo.SpeedLimit, SpeedLimit: nodeInfo.SpeedLimit,
DeviceLimit: nodeInfo.DeviceLimit, DeviceLimit: nodeInfo.DeviceLimit,
}) })
inboundInfo.BucketHub.Delete(fmt.Sprintf("%s|%s|%d", tag, inboundInfo.BucketHub.Delete(fmt.Sprintf("%s|%s|%d", tag,
(*updatedUserList)[i].V2rayUser.Email, (*updatedUserList)[i].UID)) // Delete old limiter bucket (updatedUserList)[i].V2rayUser.Email, (updatedUserList)[i].UID)) // Delete old limiter bucket
} }
} else { } else {
return fmt.Errorf("no such inbound in limiter: %s", tag) return fmt.Errorf("no such inbound in limiter: %s", tag)
@ -90,7 +91,7 @@ type UserIp struct {
IPs []string `json:"Ips"` IPs []string `json:"Ips"`
} }
func (l *Limiter) GetOnlineUserIp(tag string) (*[]UserIp, error) { func (l *Limiter) GetOnlineUserIp(tag string) ([]UserIp, error) {
if value, ok := l.InboundInfo.Load(tag); ok { if value, ok := l.InboundInfo.Load(tag); ok {
inboundInfo := value.(*InboundInfo) inboundInfo := value.(*InboundInfo)
// Clear Speed Limiter bucket for users who are not online // Clear Speed Limiter bucket for users who are not online
@ -124,13 +125,13 @@ func (l *Limiter) GetOnlineUserIp(tag string) (*[]UserIp, error) {
if len(onlineUser) == 0 { if len(onlineUser) == 0 {
return nil, nil return nil, nil
} }
return &onlineUser, nil return onlineUser, nil
} else { } else {
return nil, fmt.Errorf("no such inbound in limiter: %s", tag) return nil, fmt.Errorf("no such inbound in limiter: %s", tag)
} }
} }
func (l *Limiter) UpdateOnlineUserIP(tag string, userIpList *[]UserIp) { func (l *Limiter) UpdateOnlineUserIP(tag string, userIpList []UserIp) {
if v, ok := l.InboundInfo.Load(tag); ok { if v, ok := l.InboundInfo.Load(tag); ok {
inboundInfo := v.(*InboundInfo) inboundInfo := v.(*InboundInfo)
//Clear old IP //Clear old IP
@ -139,12 +140,12 @@ func (l *Limiter) UpdateOnlineUserIP(tag string, userIpList *[]UserIp) {
return true return true
}) })
// Update User Online IP // Update User Online IP
for i := range *userIpList { for i := range userIpList {
ipMap := new(sync.Map) ipMap := new(sync.Map)
for _, userIp := range (*userIpList)[i].IPs { for _, userIp := range (userIpList)[i].IPs {
ipMap.Store(userIp, false) ipMap.Store(userIp, false)
} }
inboundInfo.UserOnlineIP.Store((*userIpList)[i].Uid, ipMap) inboundInfo.UserOnlineIP.Store((userIpList)[i].Uid, ipMap)
} }
} }
} }

View File

@ -46,7 +46,7 @@ func (r *Rule) UpdateProtocolRule(tag string, ruleList []string) error {
return nil return nil
} }
func (r *Rule) GetDetectResult(tag string) (*[]api.DetectResult, error) { func (r *Rule) GetDetectResult(tag string) ([]api.DetectResult, error) {
detectResult := make([]api.DetectResult, 0) detectResult := make([]api.DetectResult, 0)
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok { if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
resultSet := value.(mapset.Set) resultSet := value.(mapset.Set)
@ -55,7 +55,7 @@ func (r *Rule) GetDetectResult(tag string) (*[]api.DetectResult, error) {
detectResult = append(detectResult, result.(api.DetectResult)) detectResult = append(detectResult, result.(api.DetectResult))
} }
} }
return &detectResult, nil return detectResult, nil
} }
func (r *Rule) Detect(tag string, destination string, email string) (reject bool) { func (r *Rule) Detect(tag string, destination string, email string) (reject bool) {

View File

@ -1,2 +0,0 @@
// Package common contains common utilities that are shared among other packages.
package common

2
core/app/app.go Normal file
View File

@ -0,0 +1,2 @@
// Package app contains the third-party app used to replace the default app in xray-core
package app

View File

@ -5,8 +5,8 @@ package dispatcher
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/common/limiter" "github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/common/rule" "github.com/Yuzuki616/V2bX/app/rule"
"github.com/xtls/xray-core/common" "github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log" "github.com/xtls/xray-core/common/log"

View File

@ -1,11 +1,13 @@
package xray package core
import ( import (
"encoding/json" "encoding/json"
"github.com/Yuzuki616/V2bX/app/dispatcher"
"github.com/Yuzuki616/V2bX/conf" "github.com/Yuzuki616/V2bX/conf"
_ "github.com/Yuzuki616/V2bX/xray/distro/all" "github.com/Yuzuki616/V2bX/core/app/dispatcher"
_ "github.com/Yuzuki616/V2bX/core/distro/all"
"github.com/xtls/xray-core/app/proxyman" "github.com/xtls/xray-core/app/proxyman"
"github.com/xtls/xray-core/app/proxyman/inbound"
"github.com/xtls/xray-core/app/proxyman/outbound"
"github.com/xtls/xray-core/app/stats" "github.com/xtls/xray-core/app/stats"
"github.com/xtls/xray-core/common/serial" "github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/core" "github.com/xtls/xray-core/core"
@ -15,14 +17,17 @@ import (
"sync" "sync"
) )
// Xray Structure // Core Structure
type Xray struct { type Core struct {
access sync.Mutex access sync.Mutex
Server *core.Instance Server *core.Instance
ihm *inbound.Manager
ohm *outbound.Manager
dispatcher *dispatcher.DefaultDispatcher
} }
func New(c *conf.Conf) *Xray { func New(c *conf.Conf) *Core {
return &Xray{Server: getCore(c)} return &Core{Server: getCore(c)}
} }
func parseConnectionConfig(c *conf.ConnetionConfig) (policy *coreConf.Policy) { func parseConnectionConfig(c *conf.ConnetionConfig) (policy *coreConf.Policy) {
@ -117,7 +122,7 @@ func getCore(v2bXConfig *conf.Conf) *core.Instance {
corePolicyConfig := &coreConf.PolicyConfig{} corePolicyConfig := &coreConf.PolicyConfig{}
corePolicyConfig.Levels = map[uint32]*coreConf.Policy{0: levelPolicyConfig} corePolicyConfig.Levels = map[uint32]*coreConf.Policy{0: levelPolicyConfig}
policyConfig, _ := corePolicyConfig.Build() policyConfig, _ := corePolicyConfig.Build()
// Build Xray conf // Build Core conf
config := &core.Config{ config := &core.Config{
App: []*serial.TypedMessage{ App: []*serial.TypedMessage{
serial.ToTypedMessage(coreLogConfig.Build()), serial.ToTypedMessage(coreLogConfig.Build()),
@ -136,13 +141,13 @@ func getCore(v2bXConfig *conf.Conf) *core.Instance {
if err != nil { if err != nil {
log.Panicf("failed to create instance: %s", err) log.Panicf("failed to create instance: %s", err)
} }
log.Printf("Xray Version: %s", core.Version()) log.Printf("Core Version: %s", core.Version())
return server return server
} }
// Start the Xray // Start the Core
func (p *Xray) Start() { func (p *Core) Start() {
p.access.Lock() p.access.Lock()
defer p.access.Unlock() defer p.access.Unlock()
log.Print("Start the panel..") log.Print("Start the panel..")
@ -153,7 +158,7 @@ func (p *Xray) Start() {
} }
// Close the core // Close the core
func (p *Xray) Close() { func (p *Core) Close() {
p.access.Lock() p.access.Lock()
defer p.access.Unlock() defer p.access.Unlock()
p.Server.Close() p.Server.Close()

View File

@ -5,7 +5,7 @@ import (
// Required features. Can't remove unless there is replacements. // Required features. Can't remove unless there is replacements.
// _ "github.com/xtls/xray-core/app/dispatcher" // _ "github.com/xtls/xray-core/app/dispatcher"
_ "github.com/Yuzuki616/V2bX/app/dispatcher" _ "github.com/Yuzuki616/V2bX/core/app/dispatcher"
_ "github.com/xtls/xray-core/app/proxyman/inbound" _ "github.com/xtls/xray-core/app/proxyman/inbound"
_ "github.com/xtls/xray-core/app/proxyman/outbound" _ "github.com/xtls/xray-core/app/proxyman/outbound"
@ -54,8 +54,8 @@ import (
// JSON & TOML & YAML // JSON & TOML & YAML
_ "github.com/xtls/xray-core/main/json" _ "github.com/xtls/xray-core/main/json"
_ "github.com/xtls/xray-core/main/toml" //_ "github.com/xtls/xray-core/main/toml"
_ "github.com/xtls/xray-core/main/yaml" //_ "github.com/xtls/xray-core/main/yaml"
// Load config from file or http(s) // Load config from file or http(s)
_ "github.com/xtls/xray-core/main/confloader/external" _ "github.com/xtls/xray-core/main/confloader/external"

View File

@ -1,24 +1,22 @@
package xray package core
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api" "github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/app/dispatcher" "github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/common/limiter" "github.com/Yuzuki616/V2bX/core/app/dispatcher"
"github.com/xtls/xray-core/core" "github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/inbound" "github.com/xtls/xray-core/features/inbound"
"github.com/xtls/xray-core/features/routing" "github.com/xtls/xray-core/features/routing"
) )
func (p *Xray) RemoveInbound(tag string) error { func (p *Core) RemoveInbound(tag string) error {
inboundManager := p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager) err := p.ihm.RemoveHandler(context.Background(), tag)
err := inboundManager.RemoveHandler(context.Background(), tag)
return err return err
} }
func (p *Xray) AddInbound(config *core.InboundHandlerConfig) error { func (p *Core) AddInbound(config *core.InboundHandlerConfig) error {
inboundManager := p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager)
rawHandler, err := core.CreateObject(p.Server, config) rawHandler, err := core.CreateObject(p.Server, config)
if err != nil { if err != nil {
return err return err
@ -27,19 +25,19 @@ func (p *Xray) AddInbound(config *core.InboundHandlerConfig) error {
if !ok { if !ok {
return fmt.Errorf("not an InboundHandler: %s", err) return fmt.Errorf("not an InboundHandler: %s", err)
} }
if err := inboundManager.AddHandler(context.Background(), handler); err != nil { if err := p.ihm.AddHandler(context.Background(), handler); err != nil {
return err return err
} }
return nil return nil
} }
func (p *Xray) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList *[]api.UserInfo) error { func (p *Core) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList []api.UserInfo) error {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
err := dispather.Limiter.AddInboundLimiter(tag, nodeInfo, userList) err := dispather.Limiter.AddInboundLimiter(tag, nodeInfo, userList)
return err return err
} }
func (p *Xray) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) { func (p *Core) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
limit, ok := dispather.Limiter.InboundInfo.Load(tag) limit, ok := dispather.Limiter.InboundInfo.Load(tag)
if ok { if ok {
@ -48,13 +46,13 @@ func (p *Xray) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) {
return nil, fmt.Errorf("not found limiter") return nil, fmt.Errorf("not found limiter")
} }
func (p *Xray) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList *[]api.UserInfo) error { func (p *Core) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList []api.UserInfo) error {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
err := dispather.Limiter.UpdateInboundLimiter(tag, nodeInfo, updatedUserList) err := dispather.Limiter.UpdateInboundLimiter(tag, nodeInfo, updatedUserList)
return err return err
} }
func (p *Xray) DeleteInboundLimiter(tag string) error { func (p *Core) DeleteInboundLimiter(tag string) error {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
err := dispather.Limiter.DeleteInboundLimiter(tag) err := dispather.Limiter.DeleteInboundLimiter(tag)
return err return err

View File

@ -1,4 +1,4 @@
package xray package core
import ( import (
"context" "context"
@ -7,13 +7,13 @@ import (
"github.com/xtls/xray-core/features/outbound" "github.com/xtls/xray-core/features/outbound"
) )
func (p *Xray) RemoveOutbound(tag string) error { func (p *Core) RemoveOutbound(tag string) error {
outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager) outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
err := outboundManager.RemoveHandler(context.Background(), tag) err := outboundManager.RemoveHandler(context.Background(), tag)
return err return err
} }
func (p *Xray) AddOutbound(config *core.OutboundHandlerConfig) error { func (p *Core) AddOutbound(config *core.OutboundHandlerConfig) error {
outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager) outboundManager := p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
rawHandler, err := core.CreateObject(p.Server, config) rawHandler, err := core.CreateObject(p.Server, config)
if err != nil { if err != nil {

19
core/rule.go Normal file
View File

@ -0,0 +1,19 @@
package core
import (
"github.com/Yuzuki616/V2bX/api"
)
func (p *Core) UpdateRule(tag string, newRuleList []api.DetectRule) error {
err := p.dispatcher.RuleManager.UpdateRule(tag, newRuleList)
return err
}
func (p *Core) UpdateProtocolRule(tag string, newRuleList []string) error {
err := p.dispatcher.RuleManager.UpdateProtocolRule(tag, newRuleList)
return err
}
func (p *Core) GetDetectResult(tag string) ([]api.DetectResult, error) {
return p.dispatcher.RuleManager.GetDetectResult(tag)
}

View File

@ -1,20 +1,16 @@
package xray package core
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/app/dispatcher" "github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/common/limiter"
"github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/features/inbound"
"github.com/xtls/xray-core/features/routing"
"github.com/xtls/xray-core/features/stats" "github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy" "github.com/xtls/xray-core/proxy"
) )
func (p *Xray) GetUserManager(tag string) (proxy.UserManager, error) { func (p *Core) GetUserManager(tag string) (proxy.UserManager, error) {
inboundManager := p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager) handler, err := p.ihm.GetHandler(context.Background(), tag)
handler, err := inboundManager.GetHandler(context.Background(), tag)
if err != nil { if err != nil {
return nil, fmt.Errorf("no such inbound tag: %s", err) return nil, fmt.Errorf("no such inbound tag: %s", err)
} }
@ -29,7 +25,7 @@ func (p *Xray) GetUserManager(tag string) (proxy.UserManager, error) {
return userManager, nil return userManager, nil
} }
func (p *Xray) AddUsers(users []*protocol.User, tag string) error { func (p *Core) AddUsers(users []*protocol.User, tag string) error {
userManager, err := p.GetUserManager(tag) userManager, err := p.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)
@ -47,7 +43,7 @@ func (p *Xray) AddUsers(users []*protocol.User, tag string) error {
return nil return nil
} }
func (p *Xray) RemoveUsers(users []string, tag string) error { func (p *Core) RemoveUsers(users []string, tag string) error {
userManager, err := p.GetUserManager(tag) userManager, err := p.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)
@ -61,7 +57,7 @@ func (p *Xray) RemoveUsers(users []string, tag string) error {
return nil return nil
} }
func (p *Xray) GetUserTraffic(email string) (up int64, down int64) { func (p *Core) GetUserTraffic(email string) (up int64, down int64) {
upName := "user>>>" + email + ">>>traffic>>>uplink" upName := "user>>>" + email + ">>>traffic>>>uplink"
downName := "user>>>" + email + ">>>traffic>>>downlink" downName := "user>>>" + email + ">>>traffic>>>downlink"
statsManager := p.Server.GetFeature(stats.ManagerType()).(stats.Manager) statsManager := p.Server.GetFeature(stats.ManagerType()).(stats.Manager)
@ -78,17 +74,14 @@ func (p *Xray) GetUserTraffic(email string) (up int64, down int64) {
return up, down return up, down
} }
func (p *Xray) GetOnlineIps(tag string) (*[]limiter.UserIp, error) { func (p *Core) GetOnlineIps(tag string) ([]limiter.UserIp, error) {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) return p.dispatcher.Limiter.GetOnlineUserIp(tag)
return dispather.Limiter.GetOnlineUserIp(tag)
} }
func (p *Xray) UpdateOnlineIps(tag string, ips *[]limiter.UserIp) { func (p *Core) UpdateOnlineIps(tag string, ips []limiter.UserIp) {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) p.dispatcher.Limiter.UpdateOnlineUserIP(tag, ips)
dispather.Limiter.UpdateOnlineUserIP(tag, ips)
} }
func (p *Xray) ClearOnlineIps(tag string) { func (p *Core) ClearOnlineIps(tag string) {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher) p.dispatcher.Limiter.ClearOnlineUserIP(tag)
dispather.Limiter.ClearOnlineUserIP(tag)
} }

View File

@ -5,8 +5,8 @@ import (
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api" "github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/conf" "github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/node" "github.com/Yuzuki616/V2bX/node"
"github.com/Yuzuki616/V2bX/xray"
"github.com/spf13/viper" "github.com/spf13/viper"
"log" "log"
"os" "os"
@ -25,7 +25,7 @@ var (
var ( var (
version = "v0.0.4" version = "v0.0.4"
codename = "V2bX" codename = "V2bX"
intro = "A V2board backend based on Xray" intro = "A V2board backend based on Xray-core"
) )
func showVersion() { func showVersion() {
@ -58,7 +58,7 @@ func getConfig() *viper.Viper {
return config return config
} }
func startNodes(nodes []*conf.NodeConfig, core *xray.Xray) error { func startNodes(nodes []*conf.NodeConfig, core *core.Core) error {
for i, _ := range nodes { for i, _ := range nodes {
var apiClient = api.New(nodes[i].ApiConfig) var apiClient = api.New(nodes[i].ApiConfig)
// Register controller service // Register controller service
@ -82,7 +82,7 @@ func main() {
if err != nil { if err != nil {
log.Panicf("can't unmarshal config file: %s \n", err) log.Panicf("can't unmarshal config file: %s \n", err)
} }
x := xray.New(c) x := core.New(c)
x.Start() x.Start()
defer x.Close() defer x.Close()
err = startNodes(c.NodesConfig, x) err = startNodes(c.NodesConfig, x)

View File

@ -5,7 +5,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/api" "github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/common/legoCmd" "github.com/Yuzuki616/V2bX/app/legoCmd"
"github.com/Yuzuki616/V2bX/conf" "github.com/Yuzuki616/V2bX/conf"
"github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/uuid" "github.com/xtls/xray-core/common/uuid"

View File

@ -2,9 +2,9 @@ package node
import ( import (
"fmt" "fmt"
"github.com/Yuzuki616/V2bX/common/limiter" "github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/conf" "github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/xray" "github.com/Yuzuki616/V2bX/core"
"github.com/go-resty/resty/v2" "github.com/go-resty/resty/v2"
"github.com/goccy/go-json" "github.com/goccy/go-json"
"log" "log"
@ -14,26 +14,26 @@ import (
"time" "time"
"github.com/Yuzuki616/V2bX/api" "github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/common/legoCmd" "github.com/Yuzuki616/V2bX/app/legoCmd"
"github.com/xtls/xray-core/common/protocol" "github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/task" "github.com/xtls/xray-core/common/task"
) )
type Node struct { type Node struct {
server *xray.Xray server *core.Core
config *conf.ControllerConfig config *conf.ControllerConfig
clientInfo api.ClientInfo clientInfo api.ClientInfo
apiClient api.API apiClient api.API
nodeInfo *api.NodeInfo nodeInfo *api.NodeInfo
Tag string Tag string
userList *[]api.UserInfo userList []api.UserInfo
nodeInfoMonitorPeriodic *task.Periodic nodeInfoMonitorPeriodic *task.Periodic
userReportPeriodic *task.Periodic userReportPeriodic *task.Periodic
onlineIpReportPeriodic *task.Periodic onlineIpReportPeriodic *task.Periodic
} }
// New return a Node service with default parameters. // New return a Node service with default parameters.
func New(server *xray.Xray, api api.API, config *conf.ControllerConfig) *Node { func New(server *core.Core, api api.API, config *conf.ControllerConfig) *Node {
controller := &Node{ controller := &Node{
server: server, server: server,
config: config, config: config,
@ -77,12 +77,12 @@ func (c *Node) Start() error {
if !c.config.DisableGetRule { if !c.config.DisableGetRule {
if ruleList, protocolRule, err := c.apiClient.GetNodeRule(); err != nil { if ruleList, protocolRule, err := c.apiClient.GetNodeRule(); err != nil {
log.Printf("Get rule list filed: %s", err) log.Printf("Get rule list filed: %s", err)
} else if len(*ruleList) > 0 { } else if len(ruleList) > 0 {
if err := c.server.UpdateRule(c.Tag, *ruleList); err != nil { if err := c.server.UpdateRule(c.Tag, ruleList); err != nil {
log.Print(err) log.Print(err)
} }
if len(*protocolRule) > 0 { if len(protocolRule) > 0 {
if err := c.server.UpdateProtocolRule(c.Tag, *protocolRule); err != nil { if err := c.server.UpdateProtocolRule(c.Tag, protocolRule); err != nil {
log.Print(err) log.Print(err)
} }
} }
@ -189,12 +189,12 @@ func (c *Node) nodeInfoMonitor() (err error) {
if !c.config.DisableGetRule { if !c.config.DisableGetRule {
if ruleList, protocolRule, err := c.apiClient.GetNodeRule(); err != nil { if ruleList, protocolRule, err := c.apiClient.GetNodeRule(); err != nil {
log.Printf("Get rule list filed: %s", err) log.Printf("Get rule list filed: %s", err)
} else if len(*ruleList) > 0 { } else if len(ruleList) > 0 {
if err := c.server.UpdateRule(c.Tag, *ruleList); err != nil { if err := c.server.UpdateRule(c.Tag, ruleList); err != nil {
log.Print(err) log.Print(err)
} }
if len(*protocolRule) > 0 { if len(protocolRule) > 0 {
if err := c.server.UpdateProtocolRule(c.Tag, *protocolRule); err != nil { if err := c.server.UpdateProtocolRule(c.Tag, protocolRule); err != nil {
log.Print(err) log.Print(err)
} }
} }
@ -209,7 +209,7 @@ func (c *Node) nodeInfoMonitor() (err error) {
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
// Xray-core supports the OcspStapling certification hot renew // Core-core supports the OcspStapling certification hot renew
_, _, err = lego.RenewCert(c.config.CertConfig.CertDomain, c.config.CertConfig.Email, _, _, err = lego.RenewCert(c.config.CertConfig.CertDomain, c.config.CertConfig.Email,
c.config.CertConfig.CertMode, c.config.CertConfig.Provider, c.config.CertConfig.DNSEnv) c.config.CertConfig.CertMode, c.config.CertConfig.Provider, c.config.CertConfig.DNSEnv)
if err != nil { if err != nil {
@ -239,19 +239,19 @@ func (c *Node) nodeInfoMonitor() (err error) {
runtime.GC() runtime.GC()
} else { } else {
deleted, added := compareUserList(c.userList, newUserInfo) deleted, added := compareUserList(c.userList, newUserInfo)
if len(*deleted) > 0 { if len(deleted) > 0 {
deletedEmail := make([]string, len(*deleted)) deletedEmail := make([]string, len(deleted))
for i := range *deleted { for i := range deleted {
deletedEmail[i] = fmt.Sprintf("%s|%s|%d", c.Tag, deletedEmail[i] = fmt.Sprintf("%s|%s|%d", c.Tag,
(*deleted)[i].GetUserEmail(), (deleted)[i].GetUserEmail(),
(*deleted)[i].UID) (deleted)[i].UID)
} }
err := c.server.RemoveUsers(deletedEmail, c.Tag) err := c.server.RemoveUsers(deletedEmail, c.Tag)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} }
} }
if len(*added) > 0 { if len(added) > 0 {
err = c.addNewUser(added, newNodeInfo) err = c.addNewUser(added, newNodeInfo)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -262,7 +262,7 @@ func (c *Node) nodeInfoMonitor() (err error) {
} }
} }
log.Printf("[%s: %d] %d user deleted, %d user added", c.nodeInfo.NodeType, c.nodeInfo.NodeId, log.Printf("[%s: %d] %d user deleted, %d user added", c.nodeInfo.NodeType, c.nodeInfo.NodeId,
len(*deleted), len(*added)) len(deleted), len(added))
c.userList = newUserInfo c.userList = newUserInfo
newUserInfo = nil newUserInfo = nil
runtime.GC() runtime.GC()
@ -305,14 +305,14 @@ func (c *Node) addNewTag(newNodeInfo *api.NodeInfo) (err error) {
return nil return nil
} }
func (c *Node) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo) (err error) { func (c *Node) addNewUser(userInfo []api.UserInfo, nodeInfo *api.NodeInfo) (err error) {
users := make([]*protocol.User, 0) users := make([]*protocol.User, 0)
if nodeInfo.NodeType == "V2ray" { if nodeInfo.NodeType == "V2ray" {
if nodeInfo.EnableVless { if nodeInfo.EnableVless {
users = c.buildVlessUsers(userInfo) users = c.buildVlessUsers(userInfo)
} else { } else {
alterID := 0 alterID := 0
alterID = (*userInfo)[0].V2rayUser.AlterId alterID = (userInfo)[0].V2rayUser.AlterId
if alterID >= 0 && alterID < math.MaxUint16 { if alterID >= 0 && alterID < math.MaxUint16 {
users = c.buildVmessUsers(userInfo, uint16(alterID)) users = c.buildVmessUsers(userInfo, uint16(alterID))
} else { } else {
@ -331,32 +331,32 @@ func (c *Node) addNewUser(userInfo *[]api.UserInfo, nodeInfo *api.NodeInfo) (err
if err != nil { if err != nil {
return err return err
} }
log.Printf("[%s: %d] Added %d new users", c.nodeInfo.NodeType, c.nodeInfo.NodeId, len(*userInfo)) log.Printf("[%s: %d] Added %d new users", c.nodeInfo.NodeType, c.nodeInfo.NodeId, len(userInfo))
return nil return nil
} }
func compareUserList(old, new *[]api.UserInfo) (deleted, added *[]api.UserInfo) { func compareUserList(old, new []api.UserInfo) (deleted, added []api.UserInfo) {
tmp := map[string]struct{}{} tmp := map[string]struct{}{}
tmp2 := map[string]struct{}{} tmp2 := map[string]struct{}{}
for i := range *old { for i := range old {
tmp[(*old)[i].GetUserEmail()] = struct{}{} tmp[(old)[i].GetUserEmail()] = struct{}{}
} }
l := len(tmp) l := len(tmp)
for i := range *new { for i := range new {
e := (*new)[i].GetUserEmail() e := (new)[i].GetUserEmail()
tmp[e] = struct{}{} tmp[e] = struct{}{}
tmp2[e] = struct{}{} tmp2[e] = struct{}{}
if l != len(tmp) { if l != len(tmp) {
*added = append(*added, (*new)[i]) added = append(added, (new)[i])
l++ l++
} }
} }
tmp = nil tmp = nil
l = len(tmp2) l = len(tmp2)
for i := range *old { for i := range old {
tmp2[(*old)[i].GetUserEmail()] = struct{}{} tmp2[(old)[i].GetUserEmail()] = struct{}{}
if l != len(tmp2) { if l != len(tmp2) {
*deleted = append(*deleted, (*old)[i]) deleted = append(deleted, (old)[i])
l++ l++
} }
} }
@ -366,17 +366,17 @@ func compareUserList(old, new *[]api.UserInfo) (deleted, added *[]api.UserInfo)
func (c *Node) userInfoMonitor() (err error) { func (c *Node) userInfoMonitor() (err error) {
// Get User traffic // Get User traffic
userTraffic := make([]api.UserTraffic, 0) userTraffic := make([]api.UserTraffic, 0)
for i := range *c.userList { for i := range c.userList {
up, down := c.server.GetUserTraffic(c.buildUserTag(&(*c.userList)[i])) up, down := c.server.GetUserTraffic(c.buildUserTag(&(c.userList)[i]))
if up > 0 || down > 0 { if up > 0 || down > 0 {
userTraffic = append(userTraffic, api.UserTraffic{ userTraffic = append(userTraffic, api.UserTraffic{
UID: (*c.userList)[i].UID, UID: (c.userList)[i].UID,
Upload: up, Upload: up,
Download: down}) Download: down})
} }
} }
if len(userTraffic) > 0 && !c.config.DisableUploadTraffic { if len(userTraffic) > 0 && !c.config.DisableUploadTraffic {
err = c.apiClient.ReportUserTraffic(&userTraffic) err = c.apiClient.ReportUserTraffic(userTraffic)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
} else { } else {
@ -405,9 +405,9 @@ func (c *Node) onlineIpReport() (err error) {
c.server.ClearOnlineIps(c.Tag) c.server.ClearOnlineIps(c.Tag)
return nil return nil
} }
log.Printf("[Node: %d] Report %d online ip", c.nodeInfo.NodeId, len(*onlineIp)) log.Printf("[Node: %d] Report %d online ip", c.nodeInfo.NodeId, len(onlineIp))
if rsp.StatusCode() == 200 { if rsp.StatusCode() == 200 {
onlineIp = &[]limiter.UserIp{} onlineIp = []limiter.UserIp{}
err := json.Unmarshal(rsp.Body(), onlineIp) err := json.Unmarshal(rsp.Body(), onlineIp)
if err != nil { if err != nil {
log.Print(err) log.Print(err)
@ -415,7 +415,7 @@ func (c *Node) onlineIpReport() (err error) {
return nil return nil
} }
c.server.UpdateOnlineIps(c.Tag, onlineIp) c.server.UpdateOnlineIps(c.Tag, onlineIp)
log.Printf("[Node: %d] Updated %d online ip", c.nodeInfo.NodeId, len(*onlineIp)) log.Printf("[Node: %d] Updated %d online ip", c.nodeInfo.NodeId, len(onlineIp))
} else { } else {
c.server.ClearOnlineIps(c.Tag) c.server.ClearOnlineIps(c.Tag)
} }

View File

@ -13,9 +13,9 @@ import (
"github.com/xtls/xray-core/proxy/vless" "github.com/xtls/xray-core/proxy/vless"
) )
func (c *Node) buildVmessUsers(userInfo *[]api.UserInfo, serverAlterID uint16) (users []*protocol.User) { func (c *Node) buildVmessUsers(userInfo []api.UserInfo, serverAlterID uint16) (users []*protocol.User) {
users = make([]*protocol.User, len(*userInfo)) users = make([]*protocol.User, len(userInfo))
for i, user := range *userInfo { for i, user := range userInfo {
users[i] = c.buildVmessUser(&user, serverAlterID) users[i] = c.buildVmessUser(&user, serverAlterID)
} }
return users return users
@ -35,10 +35,10 @@ func (c *Node) buildVmessUser(userInfo *api.UserInfo, serverAlterID uint16) (use
return user return user
} }
func (c *Node) buildVlessUsers(userInfo *[]api.UserInfo) (users []*protocol.User) { func (c *Node) buildVlessUsers(userInfo []api.UserInfo) (users []*protocol.User) {
users = make([]*protocol.User, len(*userInfo)) users = make([]*protocol.User, len(userInfo))
for i := range *userInfo { for i := range userInfo {
users[i] = c.buildVlessUser(&(*userInfo)[i]) users[i] = c.buildVlessUser(&(userInfo)[i])
} }
return users return users
} }
@ -56,10 +56,10 @@ func (c *Node) buildVlessUser(userInfo *api.UserInfo) (user *protocol.User) {
return user return user
} }
func (c *Node) buildTrojanUsers(userInfo *[]api.UserInfo) (users []*protocol.User) { func (c *Node) buildTrojanUsers(userInfo []api.UserInfo) (users []*protocol.User) {
users = make([]*protocol.User, len(*userInfo)) users = make([]*protocol.User, len(userInfo))
for i := range *userInfo { for i := range userInfo {
users[i] = c.buildTrojanUser(&(*userInfo)[i]) users[i] = c.buildTrojanUser(&(userInfo)[i])
} }
return users return users
} }
@ -92,10 +92,10 @@ func getCipherFromString(c string) shadowsocks.CipherType {
} }
} }
func (c *Node) buildSSUsers(userInfo *[]api.UserInfo, cypher shadowsocks.CipherType) (users []*protocol.User) { func (c *Node) buildSSUsers(userInfo []api.UserInfo, cypher shadowsocks.CipherType) (users []*protocol.User) {
users = make([]*protocol.User, len(*userInfo)) users = make([]*protocol.User, len(userInfo))
for i := range *userInfo { for i := range userInfo {
c.buildSSUser(&(*userInfo)[i], cypher) c.buildSSUser(&(userInfo)[i], cypher)
} }
return users return users
} }

View File

@ -1,24 +0,0 @@
package xray
import (
"github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/app/dispatcher"
"github.com/xtls/xray-core/features/routing"
)
func (p *Xray) UpdateRule(tag string, newRuleList []api.DetectRule) error {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
err := dispather.RuleManager.UpdateRule(tag, newRuleList)
return err
}
func (p *Xray) UpdateProtocolRule(tag string, newRuleList []string) error {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
err := dispather.RuleManager.UpdateProtocolRule(tag, newRuleList)
return err
}
func (p *Xray) GetDetectResult(tag string) (*[]api.DetectResult, error) {
dispather := p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
return dispather.RuleManager.GetDetectResult(tag)
}