change project structure, fix online ip report bug

This commit is contained in:
yuzuki999 2022-08-16 13:04:33 +08:00
parent ca180a63c9
commit 27b97927c1
41 changed files with 121 additions and 152 deletions

View File

@ -1,7 +1,7 @@
// Package api contains all the api used by XrayR
// To implement an api , one needs to implement the interface below.
package api
package panel
import (
"github.com/Yuzuki616/V2bX/conf"
@ -12,7 +12,7 @@ import (
"time"
)
// API is the interface for different panel's api.
// Panel is the interface for different panel's api.
type ClientInfo struct {
APIHost string
@ -39,7 +39,7 @@ type Client struct {
NodeRuleRspMd5 [16]byte
}
func New(apiConfig *conf.ApiConfig) API {
func New(apiConfig *conf.ApiConfig) Panel {
client := resty.New()
client.SetRetryCount(3)
if apiConfig.Timeout > 0 {

View File

@ -1,4 +1,4 @@
package api
package panel
import (
"bufio"

View File

@ -1,6 +1,6 @@
package api
package panel
type API interface {
type Panel interface {
GetNodeInfo() (nodeInfo *NodeInfo, err error)
GetUserList() (userList []UserInfo, err error)
ReportUserTraffic(userTraffic []UserTraffic) (err error)

View File

@ -1,4 +1,4 @@
package api
package panel
import (
"fmt"

View File

@ -1,4 +1,4 @@
package api
package panel
import (
"fmt"

View File

@ -1,2 +0,0 @@
// Package app contains feature implementations of XrayR.
package app

View File

@ -1,9 +0,0 @@
package limiter
import "github.com/xtls/xray-core/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}

View File

@ -1,31 +0,0 @@
package limiter
import (
"io"
"github.com/juju/ratelimit"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
)
type Writer struct {
writer buf.Writer
limiter *ratelimit.Bucket
w io.Writer
}
func (l *Limiter) RateWriter(writer buf.Writer, limiter *ratelimit.Bucket) buf.Writer {
return &Writer{
writer: writer,
limiter: limiter,
}
}
func (w *Writer) Close() error {
return common.Close(w.writer)
}
func (w *Writer) WriteMultiBuffer(mb buf.MultiBuffer) error {
w.limiter.Wait(int64(mb.Len()))
return w.writer.WriteMultiBuffer(mb)
}

View File

@ -1,9 +0,0 @@
package rule
import "github.com/xtls/xray-core/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}

View File

@ -5,8 +5,6 @@ package dispatcher
import (
"context"
"fmt"
"github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/app/rule"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/log"
@ -96,8 +94,8 @@ type DefaultDispatcher struct {
stats stats.Manager
dns dns.Client
fdns dns.FakeDNSEngine
Limiter *limiter.Limiter
RuleManager *rule.Rule
Limiter *Limiter
RuleManager *Rule
}
func init() {
@ -121,8 +119,8 @@ func (d *DefaultDispatcher) Init(config *Config, om outbound.Manager, router rou
d.router = router
d.policy = pm
d.stats = sm
d.Limiter = limiter.New()
d.RuleManager = rule.New()
d.Limiter = NewLimiter()
d.RuleManager = NewRule()
d.dns = dns
return nil
}

View File

@ -1,13 +1,15 @@
// Package limiter is to control the links that go into the dispather
package limiter
package dispatcher
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/juju/ratelimit"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/common/buf"
"io"
"sync"
"time"
"github.com/Yuzuki616/V2bX/api"
"github.com/juju/ratelimit"
)
type UserInfo struct {
@ -28,13 +30,13 @@ type Limiter struct {
InboundInfo *sync.Map // Key: Tag, Value: *InboundInfo
}
func New() *Limiter {
func NewLimiter() *Limiter {
return &Limiter{
InboundInfo: new(sync.Map),
}
}
func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList []api.UserInfo) error {
func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *panel.NodeInfo, userList []panel.UserInfo) error {
inboundInfo := &InboundInfo{
Tag: tag,
NodeSpeedLimit: nodeInfo.SpeedLimit,
@ -61,7 +63,7 @@ func (l *Limiter) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList
return nil
}
func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList []api.UserInfo) error {
func (l *Limiter) UpdateInboundLimiter(tag string, nodeInfo *panel.NodeInfo, updatedUserList []panel.UserInfo) error {
if value, ok := l.InboundInfo.Load(tag); ok {
inboundInfo := value.(*InboundInfo)
// Update User info
@ -211,6 +213,28 @@ func (l *Limiter) GetUserBucket(tag string, email string, ip string) (limiter *r
}
}
type Writer struct {
writer buf.Writer
limiter *ratelimit.Bucket
w io.Writer
}
func (l *Limiter) RateWriter(writer buf.Writer, limiter *ratelimit.Bucket) buf.Writer {
return &Writer{
writer: writer,
limiter: limiter,
}
}
func (w *Writer) Close() error {
return common.Close(w.writer)
}
func (w *Writer) WriteMultiBuffer(mb buf.MultiBuffer) error {
w.limiter.Wait(int64(mb.Len()))
return w.writer.WriteMultiBuffer(mb)
}
// determineRate returns the minimum non-zero rate
func determineRate(nodeLimit, userLimit uint64) (limit uint64) {
if nodeLimit == 0 || userLimit == 0 {

View File

@ -1,14 +1,14 @@
// Package rule is to control the audit rule behaviors
package rule
package dispatcher
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"reflect"
"strconv"
"strings"
"sync"
"github.com/Yuzuki616/V2bX/api"
mapset "github.com/deckarep/golang-set"
)
@ -18,7 +18,7 @@ type Rule struct {
InboundDetectResult *sync.Map // key: Tag, Value: mapset.NewSet []api.DetectResult
}
func New() *Rule {
func NewRule() *Rule {
return &Rule{
InboundRule: new(sync.Map),
InboundProtocolRule: new(sync.Map),
@ -26,9 +26,9 @@ func New() *Rule {
}
}
func (r *Rule) UpdateRule(tag string, newRuleList []api.DetectRule) error {
func (r *Rule) UpdateRule(tag string, newRuleList []panel.DetectRule) error {
if value, ok := r.InboundRule.LoadOrStore(tag, newRuleList); ok {
oldRuleList := value.([]api.DetectRule)
oldRuleList := value.([]panel.DetectRule)
if !reflect.DeepEqual(oldRuleList, newRuleList) {
r.InboundRule.Store(tag, newRuleList)
}
@ -46,13 +46,13 @@ func (r *Rule) UpdateProtocolRule(tag string, ruleList []string) error {
return nil
}
func (r *Rule) GetDetectResult(tag string) ([]api.DetectResult, error) {
detectResult := make([]api.DetectResult, 0)
func (r *Rule) GetDetectResult(tag string) ([]panel.DetectResult, error) {
detectResult := make([]panel.DetectResult, 0)
if value, ok := r.InboundDetectResult.LoadAndDelete(tag); ok {
resultSet := value.(mapset.Set)
it := resultSet.Iterator()
for result := range it.C {
detectResult = append(detectResult, result.(api.DetectResult))
detectResult = append(detectResult, result.(panel.DetectResult))
}
}
return detectResult, nil
@ -63,7 +63,7 @@ func (r *Rule) Detect(tag string, destination string, email string) (reject bool
var hitRuleID = -1
// If we have some rule for this inbound
if value, ok := r.InboundRule.Load(tag); ok {
ruleList := value.([]api.DetectRule)
ruleList := value.([]panel.DetectRule)
for _, r := range ruleList {
if r.Pattern.Match([]byte(destination)) {
hitRuleID = r.ID
@ -79,12 +79,12 @@ func (r *Rule) Detect(tag string, destination string, email string) (reject bool
newError(fmt.Sprintf("Record illegal behavior failed! Cannot find user's uid: %s", email)).AtDebug().WriteToLog()
return reject
}
newSet := mapset.NewSetWith(api.DetectResult{UID: uid, RuleID: hitRuleID})
newSet := mapset.NewSetWith(panel.DetectResult{UID: uid, RuleID: hitRuleID})
// If there are any hit history
if v, ok := r.InboundDetectResult.LoadOrStore(tag, newSet); ok {
resultSet := v.(mapset.Set)
// If this is a new record
if resultSet.Add(api.DetectResult{UID: uid, RuleID: hitRuleID}) {
if resultSet.Add(panel.DetectResult{UID: uid, RuleID: hitRuleID}) {
r.InboundDetectResult.Store(tag, resultSet)
}
}

View File

@ -3,8 +3,8 @@ package core
import (
"context"
"fmt"
"github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/features/inbound"
)
@ -29,20 +29,20 @@ func (p *Core) AddInbound(config *core.InboundHandlerConfig) error {
return nil
}
func (p *Core) AddInboundLimiter(tag string, nodeInfo *api.NodeInfo, userList []api.UserInfo) error {
func (p *Core) AddInboundLimiter(tag string, nodeInfo *panel.NodeInfo, userList []panel.UserInfo) error {
err := p.dispatcher.Limiter.AddInboundLimiter(tag, nodeInfo, userList)
return err
}
func (p *Core) GetInboundLimiter(tag string) (*limiter.InboundInfo, error) {
func (p *Core) GetInboundLimiter(tag string) (*dispatcher.InboundInfo, error) {
limit, ok := p.dispatcher.Limiter.InboundInfo.Load(tag)
if ok {
return limit.(*limiter.InboundInfo), nil
return limit.(*dispatcher.InboundInfo), nil
}
return nil, fmt.Errorf("not found limiter")
}
func (p *Core) UpdateInboundLimiter(tag string, nodeInfo *api.NodeInfo, updatedUserList []api.UserInfo) error {
func (p *Core) UpdateInboundLimiter(tag string, nodeInfo *panel.NodeInfo, updatedUserList []panel.UserInfo) error {
err := p.dispatcher.Limiter.UpdateInboundLimiter(tag, nodeInfo, updatedUserList)
return err
}

View File

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

View File

@ -3,7 +3,7 @@ package core
import (
"context"
"fmt"
"github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/features/stats"
"github.com/xtls/xray-core/proxy"
@ -74,11 +74,11 @@ func (p *Core) GetUserTraffic(email string) (up int64, down int64) {
return up, down
}
func (p *Core) GetOnlineIps(tag string) ([]limiter.UserIp, error) {
func (p *Core) GetOnlineIps(tag string) ([]dispatcher.UserIp, error) {
return p.dispatcher.Limiter.GetOnlineUserIp(tag)
}
func (p *Core) UpdateOnlineIps(tag string, ips []limiter.UserIp) {
func (p *Core) UpdateOnlineIps(tag string, ips []dispatcher.UserIp) {
p.dispatcher.Limiter.UpdateOnlineUserIP(tag, ips)
}

View File

@ -3,7 +3,7 @@ package main
import (
"flag"
"fmt"
"github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/node"
@ -60,7 +60,7 @@ func getConfig() *viper.Viper {
func startNodes(nodes []*conf.NodeConfig, core *core.Core) error {
for i, _ := range nodes {
var apiClient = api.New(nodes[i].ApiConfig)
var apiClient = panel.New(nodes[i].ApiConfig)
// Register controller service
err := node.New(core, apiClient, nodes[i].ControllerConfig).Start()
if err != nil {

View File

@ -4,9 +4,9 @@ package node
import (
"encoding/json"
"fmt"
"github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/app/legoCmd"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/node/legoCmd"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/uuid"
"github.com/xtls/xray-core/core"
@ -14,7 +14,7 @@ import (
)
//InboundBuilder build Inbound config for different protocol
func InboundBuilder(config *conf.ControllerConfig, nodeInfo *api.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
var proxySetting interface{}
if nodeInfo.NodeType == "V2ray" {
defer func() {
@ -47,7 +47,7 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *api.NodeInfo, tag s
nodeInfo.V2ray = nil
nodeInfo.Trojan = nil
}()
nodeInfo.V2ray = &api.V2rayConfig{}
nodeInfo.V2ray = &panel.V2rayConfig{}
nodeInfo.V2ray.Inbounds = make([]coreConf.InboundDetourConfig, 1)
nodeInfo.V2ray.Inbounds[0].Protocol = "trojan"
// Enable fallback
@ -72,7 +72,7 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *api.NodeInfo, tag s
defer func() {
nodeInfo.V2ray = nil
}()
nodeInfo.V2ray = &api.V2rayConfig{}
nodeInfo.V2ray = &panel.V2rayConfig{}
nodeInfo.V2ray.Inbounds = []coreConf.InboundDetourConfig{{Protocol: "shadowsocks"}}
proxySetting = &coreConf.ShadowsocksServerConfig{}
randomPasswd := uuid.New()

View File

@ -1,14 +1,13 @@
package node_test
import (
"github.com/Yuzuki616/V2bX/api/panel"
. "github.com/Yuzuki616/V2bX/node"
"testing"
"github.com/Yuzuki616/V2bX/api"
)
func TestBuildV2ray(t *testing.T) {
nodeInfo := &api.NodeInfo{
nodeInfo := &panel.NodeInfo{
NodeType: "V2ray",
NodeID: 1,
Port: 1145,
@ -36,7 +35,7 @@ func TestBuildV2ray(t *testing.T) {
}
func TestBuildTrojan(t *testing.T) {
nodeInfo := &api.NodeInfo{
nodeInfo := &panel.NodeInfo{
NodeType: "Trojan",
NodeID: 1,
Port: 1145,
@ -68,7 +67,7 @@ func TestBuildTrojan(t *testing.T) {
}
func TestBuildSS(t *testing.T) {
nodeInfo := &api.NodeInfo{
nodeInfo := &panel.NodeInfo{
NodeType: "Shadowsocks",
NodeID: 1,
Port: 1145,

View File

@ -7,13 +7,13 @@ import (
"encoding/pem"
"errors"
"fmt"
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"io/ioutil"
"net/url"
"os"
"path/filepath"
"strings"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"

View File

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/x509"
"encoding/json"
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"io/ioutil"
"os"
"path/filepath"
@ -11,7 +12,6 @@ import (
"strings"
"time"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/urfave/cli"

View File

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

View File

@ -3,9 +3,9 @@ package cmd
import (
"crypto"
"crypto/x509"
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"time"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"

View File

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

View File

@ -3,10 +3,10 @@ package cmd
import (
"bufio"
"fmt"
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"os"
"strings"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"

View File

@ -4,12 +4,12 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"io/ioutil"
"os"
"strings"
"time"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/certcrypto"
"github.com/go-acme/lego/v4/lego"
"github.com/go-acme/lego/v4/registration"

View File

@ -1,11 +1,11 @@
package cmd
import (
"github.com/Yuzuki616/V2bX/node/legoCmd/log"
"net"
"strings"
"time"
"github.com/Yuzuki616/V2bX/app/legoCmd/log"
"github.com/go-acme/lego/v4/challenge"
"github.com/go-acme/lego/v4/challenge/dns01"
"github.com/go-acme/lego/v4/challenge/http01"

View File

@ -5,13 +5,13 @@ package legoCmd
import (
"errors"
"fmt"
cmd2 "github.com/Yuzuki616/V2bX/node/legoCmd/cmd"
"os"
"path"
"path/filepath"
"runtime"
"strings"
"github.com/Yuzuki616/V2bX/app/legoCmd/cmd"
"github.com/urfave/cli"
)
@ -47,11 +47,11 @@ func New() (*LegoCMD, error) {
defaultPath = filepath.Join(pathTemp, "cert")
app.Flags = cmd.CreateFlags(defaultPath)
app.Flags = cmd2.CreateFlags(defaultPath)
app.Before = cmd.Before
app.Before = cmd2.Before
app.Commands = cmd.CreateCommands()
app.Commands = cmd2.CreateCommands()
lego := &LegoCMD{
cmdClient: app,

View File

@ -1,9 +1,8 @@
package legoCmd_test
import (
"github.com/Yuzuki616/V2bX/node/legoCmd"
"testing"
"github.com/Yuzuki616/V2bX/app/legoCmd"
)
func TestLegoClient(t *testing.T) {

View File

@ -2,38 +2,37 @@ package node
import (
"fmt"
"github.com/Yuzuki616/V2bX/app/limiter"
"github.com/Yuzuki616/V2bX/api/panel"
"github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/core"
"github.com/Yuzuki616/V2bX/core/app/dispatcher"
"github.com/Yuzuki616/V2bX/node/legoCmd"
"github.com/go-resty/resty/v2"
"github.com/goccy/go-json"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/task"
"log"
"math"
"reflect"
"runtime"
"time"
"github.com/Yuzuki616/V2bX/api"
"github.com/Yuzuki616/V2bX/app/legoCmd"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/task"
)
type Node struct {
server *core.Core
config *conf.ControllerConfig
clientInfo api.ClientInfo
apiClient api.API
nodeInfo *api.NodeInfo
clientInfo panel.ClientInfo
apiClient panel.Panel
nodeInfo *panel.NodeInfo
Tag string
userList []api.UserInfo
userList []panel.UserInfo
nodeInfoMonitorPeriodic *task.Periodic
userReportPeriodic *task.Periodic
onlineIpReportPeriodic *task.Periodic
}
// New return a Node service with default parameters.
func New(server *core.Core, api api.API, config *conf.ControllerConfig) *Node {
func New(server *core.Core, api panel.Panel, config *conf.ControllerConfig) *Node {
controller := &Node{
server: server,
config: config,
@ -280,7 +279,7 @@ func (c *Node) removeOldTag(oldtag string) (err error) {
return nil
}
func (c *Node) addNewTag(newNodeInfo *api.NodeInfo) (err error) {
func (c *Node) addNewTag(newNodeInfo *panel.NodeInfo) (err error) {
inboundConfig, err := InboundBuilder(c.config, newNodeInfo, c.Tag)
if err != nil {
return err
@ -303,7 +302,7 @@ func (c *Node) addNewTag(newNodeInfo *api.NodeInfo) (err error) {
return nil
}
func (c *Node) addNewUser(userInfo []api.UserInfo, nodeInfo *api.NodeInfo) (err error) {
func (c *Node) addNewUser(userInfo []panel.UserInfo, nodeInfo *panel.NodeInfo) (err error) {
users := make([]*protocol.User, 0)
if nodeInfo.NodeType == "V2ray" {
if nodeInfo.EnableVless {
@ -333,7 +332,7 @@ func (c *Node) addNewUser(userInfo []api.UserInfo, nodeInfo *api.NodeInfo) (err
return nil
}
func compareUserList(old, new []api.UserInfo) (deleted, added []api.UserInfo) {
func compareUserList(old, new []panel.UserInfo) (deleted, added []panel.UserInfo) {
tmp := map[string]struct{}{}
tmp2 := map[string]struct{}{}
for i := range old {
@ -363,11 +362,11 @@ func compareUserList(old, new []api.UserInfo) (deleted, added []api.UserInfo) {
func (c *Node) userInfoMonitor() (err error) {
// Get User traffic
userTraffic := make([]api.UserTraffic, 0)
userTraffic := make([]panel.UserTraffic, 0)
for i := range c.userList {
up, down := c.server.GetUserTraffic(c.buildUserTag(&(c.userList)[i]))
if up > 0 || down > 0 {
userTraffic = append(userTraffic, api.UserTraffic{
userTraffic = append(userTraffic, panel.UserTraffic{
UID: (c.userList)[i].UID,
Upload: up,
Download: down})
@ -406,8 +405,8 @@ func (c *Node) onlineIpReport() (err error) {
}
log.Printf("[Node: %d] Report %d online ip", c.nodeInfo.NodeId, len(onlineIp))
if rsp.StatusCode() == 200 {
onlineIp = []limiter.UserIp{}
err := json.Unmarshal(rsp.Body(), onlineIp)
onlineIp = []dispatcher.UserIp{}
err := json.Unmarshal(rsp.Body(), &onlineIp)
if err != nil {
log.Print(err)
c.server.ClearOnlineIps(c.Tag)

View File

@ -2,6 +2,7 @@ package node_test
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
. "github.com/Yuzuki616/V2bX/node"
"os"
"os/signal"
@ -60,7 +61,7 @@ func TestController(t *testing.T) {
NodeID: 41,
NodeType: "V2ray",
}
apiclient := api.New(apiConfig)
apiclient := panel.New(apiConfig)
c := New(server, apiclient, controlerconfig)
fmt.Println("Sleep 1s")
err = c.Start()

View File

@ -3,16 +3,16 @@ package node
import (
"encoding/json"
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
conf2 "github.com/Yuzuki616/V2bX/conf"
"github.com/Yuzuki616/V2bX/api"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/core"
"github.com/xtls/xray-core/infra/conf"
)
//OutboundBuilder build freedom outbund config for addoutbound
func OutboundBuilder(config *conf2.ControllerConfig, nodeInfo *api.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
func OutboundBuilder(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
outboundDetourConfig := &conf.OutboundDetourConfig{}
outboundDetourConfig.Protocol = "freedom"
outboundDetourConfig.Tag = tag

View File

@ -2,9 +2,9 @@ package node
import (
"fmt"
"github.com/Yuzuki616/V2bX/api/panel"
"strings"
"github.com/Yuzuki616/V2bX/api"
"github.com/xtls/xray-core/common/protocol"
"github.com/xtls/xray-core/common/serial"
"github.com/xtls/xray-core/infra/conf"
@ -13,7 +13,7 @@ import (
"github.com/xtls/xray-core/proxy/vless"
)
func (c *Node) buildVmessUsers(userInfo []api.UserInfo, serverAlterID uint16) (users []*protocol.User) {
func (c *Node) buildVmessUsers(userInfo []panel.UserInfo, serverAlterID uint16) (users []*protocol.User) {
users = make([]*protocol.User, len(userInfo))
for i, user := range userInfo {
users[i] = c.buildVmessUser(&user, serverAlterID)
@ -21,7 +21,7 @@ func (c *Node) buildVmessUsers(userInfo []api.UserInfo, serverAlterID uint16) (u
return users
}
func (c *Node) buildVmessUser(userInfo *api.UserInfo, serverAlterID uint16) (user *protocol.User) {
func (c *Node) buildVmessUser(userInfo *panel.UserInfo, serverAlterID uint16) (user *protocol.User) {
vmessAccount := &conf.VMessAccount{
ID: userInfo.V2rayUser.Uuid,
AlterIds: serverAlterID,
@ -35,7 +35,7 @@ func (c *Node) buildVmessUser(userInfo *api.UserInfo, serverAlterID uint16) (use
return user
}
func (c *Node) buildVlessUsers(userInfo []api.UserInfo) (users []*protocol.User) {
func (c *Node) buildVlessUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
users = make([]*protocol.User, len(userInfo))
for i := range userInfo {
users[i] = c.buildVlessUser(&(userInfo)[i])
@ -43,7 +43,7 @@ func (c *Node) buildVlessUsers(userInfo []api.UserInfo) (users []*protocol.User)
return users
}
func (c *Node) buildVlessUser(userInfo *api.UserInfo) (user *protocol.User) {
func (c *Node) buildVlessUser(userInfo *panel.UserInfo) (user *protocol.User) {
vlessAccount := &vless.Account{
Id: userInfo.V2rayUser.Uuid,
Flow: "xtls-rprx-direct",
@ -56,7 +56,7 @@ func (c *Node) buildVlessUser(userInfo *api.UserInfo) (user *protocol.User) {
return user
}
func (c *Node) buildTrojanUsers(userInfo []api.UserInfo) (users []*protocol.User) {
func (c *Node) buildTrojanUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
users = make([]*protocol.User, len(userInfo))
for i := range userInfo {
users[i] = c.buildTrojanUser(&(userInfo)[i])
@ -64,7 +64,7 @@ func (c *Node) buildTrojanUsers(userInfo []api.UserInfo) (users []*protocol.User
return users
}
func (c *Node) buildTrojanUser(userInfo *api.UserInfo) (user *protocol.User) {
func (c *Node) buildTrojanUser(userInfo *panel.UserInfo) (user *protocol.User) {
trojanAccount := &trojan.Account{
Password: userInfo.TrojanUser.Password,
Flow: "xtls-rprx-direct",
@ -92,7 +92,7 @@ func getCipherFromString(c string) shadowsocks.CipherType {
}
}
func (c *Node) buildSSUsers(userInfo []api.UserInfo, cypher shadowsocks.CipherType) (users []*protocol.User) {
func (c *Node) buildSSUsers(userInfo []panel.UserInfo, cypher shadowsocks.CipherType) (users []*protocol.User) {
users = make([]*protocol.User, len(userInfo))
for i := range userInfo {
c.buildSSUser(&(userInfo)[i], cypher)
@ -100,7 +100,7 @@ func (c *Node) buildSSUsers(userInfo []api.UserInfo, cypher shadowsocks.CipherTy
return users
}
func (c *Node) buildSSUser(userInfo *api.UserInfo, cypher shadowsocks.CipherType) (user *protocol.User) {
func (c *Node) buildSSUser(userInfo *panel.UserInfo, cypher shadowsocks.CipherType) (user *protocol.User) {
ssAccount := &shadowsocks.Account{
Password: userInfo.Secret,
CipherType: cypher,
@ -113,6 +113,6 @@ func (c *Node) buildSSUser(userInfo *api.UserInfo, cypher shadowsocks.CipherType
return user
}
func (c *Node) buildUserTag(user *api.UserInfo) string {
func (c *Node) buildUserTag(user *panel.UserInfo) string {
return fmt.Sprintf("%s|%s|%d", c.Tag, user.GetUserEmail(), user.UID)
}