mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-02-02 06:48:14 -05:00
fix rule unmarshal bug, change some error message, remove alterID support
This commit is contained in:
parent
5079a13c5d
commit
231678cc8d
@ -242,7 +242,7 @@ func (c *Client) ParseV2rayNodeResponse(body []byte, notParseNode, parseRule boo
|
|||||||
}
|
}
|
||||||
if parseRule {
|
if parseRule {
|
||||||
c.RemoteRuleCache = []Rule{}
|
c.RemoteRuleCache = []Rule{}
|
||||||
err := json.Unmarshal(node.V2ray.Routing.Rules, c.RemoteRuleCache)
|
err := json.Unmarshal(node.V2ray.Routing.Rules, &c.RemoteRuleCache)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -150,18 +150,17 @@ func getCore(v2bXConfig *conf.Conf) *core.Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the Core
|
// Start the Core
|
||||||
func (p *Core) Start() {
|
func (p *Core) Start() error {
|
||||||
p.access.Lock()
|
p.access.Lock()
|
||||||
defer p.access.Unlock()
|
defer p.access.Unlock()
|
||||||
log.Print("Start the panel..")
|
|
||||||
if err := p.Server.Start(); err != nil {
|
if err := p.Server.Start(); err != nil {
|
||||||
log.Panicf("Failed to start instance: %s", err)
|
return err
|
||||||
}
|
}
|
||||||
p.shm = p.Server.GetFeature(statsFeature.ManagerType()).(statsFeature.Manager)
|
p.shm = p.Server.GetFeature(statsFeature.ManagerType()).(statsFeature.Manager)
|
||||||
p.ihm = p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager)
|
p.ihm = p.Server.GetFeature(inbound.ManagerType()).(inbound.Manager)
|
||||||
p.ohm = p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
|
p.ohm = p.Server.GetFeature(outbound.ManagerType()).(outbound.Manager)
|
||||||
p.dispatcher = p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
|
p.dispatcher = p.Server.GetFeature(routing.DispatcherType()).(*dispatcher.DefaultDispatcher)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the core
|
// Close the core
|
||||||
|
10
main.go
10
main.go
@ -35,7 +35,7 @@ func startNodes(nodes []*conf.NodeConfig, core *core.Core) error {
|
|||||||
// Register controller service
|
// Register controller service
|
||||||
err := node.New(core, apiClient, nodes[i].ControllerConfig).Start()
|
err := node.New(core, apiClient, nodes[i].ControllerConfig).Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("start node controller error: %v", err)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -52,12 +52,16 @@ 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)
|
||||||
}
|
}
|
||||||
|
log.Println("Start V2bX...")
|
||||||
x := core.New(config)
|
x := core.New(config)
|
||||||
x.Start()
|
err = x.Start()
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Failed to start core: %s", err)
|
||||||
|
}
|
||||||
defer x.Close()
|
defer x.Close()
|
||||||
err = startNodes(config.NodesConfig, x)
|
err = startNodes(config.NodesConfig, x)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("run nodes error: %v", err)
|
log.Panicf("run nodes error: %s", err)
|
||||||
}
|
}
|
||||||
//Explicitly triggering GC to remove garbage from config loading.
|
//Explicitly triggering GC to remove garbage from config loading.
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
@ -13,17 +13,19 @@ import (
|
|||||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
//InboundBuilder build Inbound config for different protocol
|
// buildInbound build Inbound config for different protocol
|
||||||
func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
func buildInbound(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.InboundHandlerConfig, error) {
|
||||||
var proxySetting interface{}
|
var proxySetting interface{}
|
||||||
if nodeInfo.NodeType == "V2ray" {
|
if nodeInfo.NodeType == "V2ray" {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
//Clear v2ray config
|
||||||
nodeInfo.V2ray = nil
|
nodeInfo.V2ray = nil
|
||||||
}()
|
}()
|
||||||
if nodeInfo.EnableVless {
|
if nodeInfo.EnableVless {
|
||||||
|
//Set vless
|
||||||
nodeInfo.V2ray.Inbounds[0].Protocol = "vless"
|
nodeInfo.V2ray.Inbounds[0].Protocol = "vless"
|
||||||
// Enable fallback
|
|
||||||
if config.EnableFallback {
|
if config.EnableFallback {
|
||||||
|
// Set fallback
|
||||||
fallbackConfigs, err := buildVlessFallbacks(config.FallBackConfigs)
|
fallbackConfigs, err := buildVlessFallbacks(config.FallBackConfigs)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
proxySetting = &coreConf.VLessInboundConfig{
|
proxySetting = &coreConf.VLessInboundConfig{
|
||||||
@ -39,19 +41,21 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Set vmess
|
||||||
nodeInfo.V2ray.Inbounds[0].Protocol = "vmess"
|
nodeInfo.V2ray.Inbounds[0].Protocol = "vmess"
|
||||||
proxySetting = &coreConf.VMessInboundConfig{}
|
proxySetting = &coreConf.VMessInboundConfig{}
|
||||||
}
|
}
|
||||||
} else if nodeInfo.NodeType == "Trojan" {
|
} else if nodeInfo.NodeType == "Trojan" {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
//clear trojan and v2ray config
|
||||||
nodeInfo.V2ray = nil
|
nodeInfo.V2ray = nil
|
||||||
nodeInfo.Trojan = nil
|
nodeInfo.Trojan = nil
|
||||||
}()
|
}()
|
||||||
nodeInfo.V2ray = &panel.V2rayConfig{}
|
nodeInfo.V2ray = &panel.V2rayConfig{}
|
||||||
nodeInfo.V2ray.Inbounds = make([]coreConf.InboundDetourConfig, 1)
|
nodeInfo.V2ray.Inbounds = make([]coreConf.InboundDetourConfig, 1)
|
||||||
nodeInfo.V2ray.Inbounds[0].Protocol = "trojan"
|
nodeInfo.V2ray.Inbounds[0].Protocol = "trojan"
|
||||||
// Enable fallback
|
|
||||||
if config.EnableFallback {
|
if config.EnableFallback {
|
||||||
|
// Set fallback
|
||||||
fallbackConfigs, err := buildTrojanFallbacks(config.FallBackConfigs)
|
fallbackConfigs, err := buildTrojanFallbacks(config.FallBackConfigs)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
proxySetting = &coreConf.TrojanServerConfig{
|
proxySetting = &coreConf.TrojanServerConfig{
|
||||||
@ -70,6 +74,7 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting = &coreConf.StreamConfig{Network: &t}
|
nodeInfo.V2ray.Inbounds[0].StreamSetting = &coreConf.StreamConfig{Network: &t}
|
||||||
} else if nodeInfo.NodeType == "Shadowsocks" {
|
} else if nodeInfo.NodeType == "Shadowsocks" {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
//Clear v2ray config
|
||||||
nodeInfo.V2ray = nil
|
nodeInfo.V2ray = nil
|
||||||
}()
|
}()
|
||||||
nodeInfo.V2ray = &panel.V2rayConfig{}
|
nodeInfo.V2ray = &panel.V2rayConfig{}
|
||||||
@ -94,18 +99,7 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting = &coreConf.StreamConfig{Network: &t}
|
nodeInfo.V2ray.Inbounds[0].StreamSetting = &coreConf.StreamConfig{Network: &t}
|
||||||
} else {
|
} else {
|
||||||
return nil, fmt.Errorf("unsupported node type: %s, Only support: V2ray, Trojan, Shadowsocks", nodeInfo.NodeType)
|
return nil, fmt.Errorf("unsupported node type: %s, Only support: V2ray, Trojan, Shadowsocks", nodeInfo.NodeType)
|
||||||
} /*else if nodeInfo.NodeType == "dokodemo-door" {
|
}
|
||||||
nodeInfo.V2ray = &api.V2rayConfig{}
|
|
||||||
nodeInfo.V2ray.Inbounds = make([]coreConf.InboundDetourConfig, 1)
|
|
||||||
nodeInfo.V2ray.Inbounds[0].Protocol = "dokodemo-door"
|
|
||||||
proxySetting = struct {
|
|
||||||
Host string `json:"address"`
|
|
||||||
NetworkList []string `json:"network"`
|
|
||||||
}{
|
|
||||||
Host: "v1.mux.cool",
|
|
||||||
NetworkList: []string{"tcp", "udp"},
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
// Build Listen IP address
|
// Build Listen IP address
|
||||||
ipAddress := net.ParseAddress(config.ListenIP)
|
ipAddress := net.ParseAddress(config.ListenIP)
|
||||||
nodeInfo.V2ray.Inbounds[0].ListenOn = &coreConf.Address{Address: ipAddress}
|
nodeInfo.V2ray.Inbounds[0].ListenOn = &coreConf.Address{Address: ipAddress}
|
||||||
@ -122,7 +116,6 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
var setting json.RawMessage
|
var setting json.RawMessage
|
||||||
|
|
||||||
// Build Protocol and Protocol setting
|
// Build Protocol and Protocol setting
|
||||||
|
|
||||||
setting, err := json.Marshal(proxySetting)
|
setting, err := json.Marshal(proxySetting)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
return nil, fmt.Errorf("marshal proxy %s config fialed: %s", nodeInfo.NodeType, err)
|
||||||
@ -133,12 +126,12 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
} else {
|
} else {
|
||||||
tcpSetting := &coreConf.TCPConfig{
|
tcpSetting := &coreConf.TCPConfig{
|
||||||
AcceptProxyProtocol: config.EnableProxyProtocol,
|
AcceptProxyProtocol: config.EnableProxyProtocol,
|
||||||
}
|
} //Enable proxy protocol
|
||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting.TCPSettings = tcpSetting
|
nodeInfo.V2ray.Inbounds[0].StreamSetting.TCPSettings = tcpSetting
|
||||||
}
|
}
|
||||||
} else if *nodeInfo.V2ray.Inbounds[0].StreamSetting.Network == "ws" {
|
} else if *nodeInfo.V2ray.Inbounds[0].StreamSetting.Network == "ws" {
|
||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting.WSSettings = &coreConf.WebSocketConfig{
|
nodeInfo.V2ray.Inbounds[0].StreamSetting.WSSettings = &coreConf.WebSocketConfig{
|
||||||
AcceptProxyProtocol: config.EnableProxyProtocol}
|
AcceptProxyProtocol: config.EnableProxyProtocol} //Enable proxy protocol
|
||||||
}
|
}
|
||||||
// Build TLS and XTLS settings
|
// Build TLS and XTLS settings
|
||||||
if nodeInfo.EnableTls && config.CertConfig.CertMode != "none" {
|
if nodeInfo.EnableTls && config.CertConfig.CertMode != "none" {
|
||||||
@ -152,7 +145,6 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
RejectUnknownSNI: config.CertConfig.RejectUnknownSni,
|
||||||
}
|
}
|
||||||
tlsSettings.Certs = append(tlsSettings.Certs, &coreConf.TLSCertConfig{CertFile: certFile, KeyFile: keyFile, OcspStapling: 3600})
|
tlsSettings.Certs = append(tlsSettings.Certs, &coreConf.TLSCertConfig{CertFile: certFile, KeyFile: keyFile, OcspStapling: 3600})
|
||||||
|
|
||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting.TLSSettings = tlsSettings
|
nodeInfo.V2ray.Inbounds[0].StreamSetting.TLSSettings = tlsSettings
|
||||||
} else if nodeInfo.TLSType == "xtls" {
|
} else if nodeInfo.TLSType == "xtls" {
|
||||||
xtlsSettings := &coreConf.XTLSConfig{
|
xtlsSettings := &coreConf.XTLSConfig{
|
||||||
@ -171,7 +163,7 @@ func InboundBuilder(config *conf.ControllerConfig, nodeInfo *panel.NodeInfo, tag
|
|||||||
config.EnableProxyProtocol {
|
config.EnableProxyProtocol {
|
||||||
sockoptConfig := &coreConf.SocketConfig{
|
sockoptConfig := &coreConf.SocketConfig{
|
||||||
AcceptProxyProtocol: config.EnableProxyProtocol,
|
AcceptProxyProtocol: config.EnableProxyProtocol,
|
||||||
}
|
} //Enable proxy protocol
|
||||||
nodeInfo.V2ray.Inbounds[0].StreamSetting.SocketSettings = sockoptConfig
|
nodeInfo.V2ray.Inbounds[0].StreamSetting.SocketSettings = sockoptConfig
|
||||||
}
|
}
|
||||||
nodeInfo.V2ray.Inbounds[0].Settings = &setting
|
nodeInfo.V2ray.Inbounds[0].Settings = &setting
|
@ -28,7 +28,7 @@ func TestBuildV2ray(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := buildInbound(config, nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func TestBuildTrojan(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := buildInbound(config, nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ func TestBuildSS(t *testing.T) {
|
|||||||
config := &Config{
|
config := &Config{
|
||||||
CertConfig: certConfig,
|
CertConfig: certConfig,
|
||||||
}
|
}
|
||||||
_, err := InboundBuilder(config, nodeInfo)
|
_, err := buildInbound(config, nodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
33
node/node.go
33
node/node.go
@ -1,13 +1,13 @@
|
|||||||
package node
|
package node
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Yuzuki616/V2bX/api/panel"
|
"github.com/Yuzuki616/V2bX/api/panel"
|
||||||
"github.com/Yuzuki616/V2bX/conf"
|
"github.com/Yuzuki616/V2bX/conf"
|
||||||
"github.com/Yuzuki616/V2bX/core"
|
"github.com/Yuzuki616/V2bX/core"
|
||||||
"github.com/xtls/xray-core/common/task"
|
"github.com/xtls/xray-core/common/task"
|
||||||
"log"
|
"log"
|
||||||
"runtime"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,27 +41,29 @@ func (c *Node) Start() error {
|
|||||||
// First fetch Node Info
|
// First fetch Node Info
|
||||||
newNodeInfo, err := c.apiClient.GetNodeInfo()
|
newNodeInfo, err := c.apiClient.GetNodeInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("get node info failed: %s", err)
|
||||||
}
|
}
|
||||||
c.nodeInfo = newNodeInfo
|
c.nodeInfo = newNodeInfo
|
||||||
c.Tag = c.buildNodeTag()
|
c.Tag = c.buildNodeTag()
|
||||||
// Add new tag
|
// Add new tag
|
||||||
err = c.addNewTag(newNodeInfo)
|
err = c.addNewTag(newNodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
return fmt.Errorf("add new tag failed: %s", err)
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
// Update user
|
// Update user
|
||||||
c.userList, err = c.apiClient.GetUserList()
|
c.userList, err = c.apiClient.GetUserList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return fmt.Errorf("get user list failed: %s", err)
|
||||||
|
}
|
||||||
|
if len(c.userList) == 0 {
|
||||||
|
return errors.New("add users failed: not have any user")
|
||||||
}
|
}
|
||||||
err = c.addNewUser(c.userList, newNodeInfo)
|
err = c.addNewUser(c.userList, newNodeInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.server.AddInboundLimiter(c.Tag, c.nodeInfo); err != nil {
|
if err := c.server.AddInboundLimiter(c.Tag, c.nodeInfo); err != nil {
|
||||||
log.Print(err)
|
return fmt.Errorf("add inbound limiter failed: %s", err)
|
||||||
}
|
}
|
||||||
// Add Rule Manager
|
// Add Rule Manager
|
||||||
if !c.config.DisableGetRule {
|
if !c.config.DisableGetRule {
|
||||||
@ -69,17 +71,19 @@ func (c *Node) Start() error {
|
|||||||
log.Printf("Get rule list filed: %s", err)
|
log.Printf("Get rule list filed: %s", err)
|
||||||
} else if ruleList != nil {
|
} else if ruleList != nil {
|
||||||
if err := c.server.UpdateRule(c.Tag, ruleList); err != nil {
|
if err := c.server.UpdateRule(c.Tag, ruleList); err != nil {
|
||||||
log.Print(err)
|
log.Printf("Update rule filed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// fetch node info task
|
||||||
c.nodeInfoMonitorPeriodic = &task.Periodic{
|
c.nodeInfoMonitorPeriodic = &task.Periodic{
|
||||||
Interval: time.Duration(c.config.UpdatePeriodic) * time.Second,
|
Interval: time.Duration(c.config.UpdatePeriodic) * time.Second,
|
||||||
Execute: c.nodeInfoMonitor,
|
Execute: c.nodeInfoMonitor,
|
||||||
}
|
}
|
||||||
|
// fetch user list task
|
||||||
c.userReportPeriodic = &task.Periodic{
|
c.userReportPeriodic = &task.Periodic{
|
||||||
Interval: time.Duration(c.config.UpdatePeriodic) * time.Second,
|
Interval: time.Duration(c.config.UpdatePeriodic) * time.Second,
|
||||||
Execute: c.userInfoMonitor,
|
Execute: c.reportUserTraffic,
|
||||||
}
|
}
|
||||||
log.Printf("[%s: %d] Start monitor node status", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
log.Printf("[%s: %d] Start monitor node status", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
||||||
// delay to start nodeInfoMonitor
|
// delay to start nodeInfoMonitor
|
||||||
@ -95,9 +99,10 @@ func (c *Node) Start() error {
|
|||||||
_ = c.userReportPeriodic.Start()
|
_ = c.userReportPeriodic.Start()
|
||||||
}()
|
}()
|
||||||
if c.config.EnableIpRecorder {
|
if c.config.EnableIpRecorder {
|
||||||
|
// report and fetch online ip list task
|
||||||
c.onlineIpReportPeriodic = &task.Periodic{
|
c.onlineIpReportPeriodic = &task.Periodic{
|
||||||
Interval: time.Duration(c.config.IpRecorderConfig.Periodic) * time.Second,
|
Interval: time.Duration(c.config.IpRecorderConfig.Periodic) * time.Second,
|
||||||
Execute: c.onlineIpReport,
|
Execute: c.reportOnlineIp,
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(c.config.IpRecorderConfig.Periodic) * time.Second)
|
time.Sleep(time.Duration(c.config.IpRecorderConfig.Periodic) * time.Second)
|
||||||
@ -106,9 +111,10 @@ func (c *Node) Start() error {
|
|||||||
log.Printf("[%s: %d] Start report online ip", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
log.Printf("[%s: %d] Start report online ip", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
||||||
}
|
}
|
||||||
if c.config.EnableDynamicSpeedLimit {
|
if c.config.EnableDynamicSpeedLimit {
|
||||||
|
// Check dynamic speed limit task
|
||||||
c.DynamicSpeedLimitPeriodic = &task.Periodic{
|
c.DynamicSpeedLimitPeriodic = &task.Periodic{
|
||||||
Interval: time.Duration(c.config.DynamicSpeedLimitConfig.Periodic) * time.Second,
|
Interval: time.Duration(c.config.DynamicSpeedLimitConfig.Periodic) * time.Second,
|
||||||
Execute: c.DynamicSpeedLimit,
|
Execute: c.dynamicSpeedLimit,
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(time.Duration(c.config.DynamicSpeedLimitConfig.Periodic) * time.Second)
|
time.Sleep(time.Duration(c.config.DynamicSpeedLimitConfig.Periodic) * time.Second)
|
||||||
@ -116,7 +122,6 @@ func (c *Node) Start() error {
|
|||||||
}()
|
}()
|
||||||
log.Printf("[%s: %d] Start dynamic speed limit", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
log.Printf("[%s: %d] Start dynamic speed limit", c.nodeInfo.NodeType, c.nodeInfo.NodeId)
|
||||||
}
|
}
|
||||||
runtime.GC()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,6 +146,12 @@ func (c *Node) Close() error {
|
|||||||
log.Panicf("online ip report periodic close failed: %s", err)
|
log.Panicf("online ip report periodic close failed: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if c.DynamicSpeedLimitPeriodic != nil {
|
||||||
|
err := c.DynamicSpeedLimitPeriodic.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("dynamic speed limit periodic close failed: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ import (
|
|||||||
"github.com/xtls/xray-core/infra/conf"
|
"github.com/xtls/xray-core/infra/conf"
|
||||||
)
|
)
|
||||||
|
|
||||||
//OutboundBuilder build freedom outbund config for addoutbound
|
// buildOutbound build freedom outbund config for addoutbound
|
||||||
func OutboundBuilder(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
func buildOutbound(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, tag string) (*core.OutboundHandlerConfig, error) {
|
||||||
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
outboundDetourConfig := &conf.OutboundDetourConfig{}
|
||||||
outboundDetourConfig.Protocol = "freedom"
|
outboundDetourConfig.Protocol = "freedom"
|
||||||
outboundDetourConfig.Tag = tag
|
outboundDetourConfig.Tag = tag
|
||||||
@ -35,10 +35,6 @@ func OutboundBuilder(config *conf2.ControllerConfig, nodeInfo *panel.NodeInfo, t
|
|||||||
proxySetting := &conf.FreedomConfig{
|
proxySetting := &conf.FreedomConfig{
|
||||||
DomainStrategy: domainStrategy,
|
DomainStrategy: domainStrategy,
|
||||||
}
|
}
|
||||||
// Used for Shadowsocks-Plugin
|
|
||||||
if nodeInfo.NodeType == "dokodemo-door" {
|
|
||||||
proxySetting.Redirect = fmt.Sprintf("127.0.0.1:%d", nodeInfo.V2ray.Inbounds[0].PortList.Range[0].From-1)
|
|
||||||
}
|
|
||||||
var setting json.RawMessage
|
var setting json.RawMessage
|
||||||
setting, err := json.Marshal(proxySetting)
|
setting, err := json.Marshal(proxySetting)
|
||||||
if err != nil {
|
if err != nil {
|
24
node/task.go
24
node/task.go
@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
"github.com/xtls/xray-core/common/protocol"
|
"github.com/xtls/xray-core/common/protocol"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
@ -118,6 +117,7 @@ func (c *Node) nodeInfoMonitor() (err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(added) > 0 || len(deleted) > 0 {
|
if len(added) > 0 || len(deleted) > 0 {
|
||||||
|
defer runtime.GC()
|
||||||
// Update Limiter
|
// Update Limiter
|
||||||
if err := c.server.UpdateInboundLimiter(c.Tag, deleted); err != nil {
|
if err := c.server.UpdateInboundLimiter(c.Tag, deleted); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -127,7 +127,6 @@ func (c *Node) nodeInfoMonitor() (err error) {
|
|||||||
len(deleted), len(added))
|
len(deleted), len(added))
|
||||||
c.userList = newUserInfo
|
c.userList = newUserInfo
|
||||||
newUserInfo = nil
|
newUserInfo = nil
|
||||||
runtime.GC()
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -145,7 +144,7 @@ func (c *Node) removeOldTag(oldTag string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) addNewTag(newNodeInfo *panel.NodeInfo) (err error) {
|
func (c *Node) addNewTag(newNodeInfo *panel.NodeInfo) (err error) {
|
||||||
inboundConfig, err := InboundBuilder(c.config, newNodeInfo, c.Tag)
|
inboundConfig, err := buildInbound(c.config, newNodeInfo, c.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -154,7 +153,7 @@ func (c *Node) addNewTag(newNodeInfo *panel.NodeInfo) (err error) {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
outBoundConfig, err := OutboundBuilder(c.config, newNodeInfo, c.Tag)
|
outBoundConfig, err := buildOutbound(c.config, newNodeInfo, c.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@ -173,14 +172,7 @@ func (c *Node) addNewUser(userInfo []panel.UserInfo, nodeInfo *panel.NodeInfo) (
|
|||||||
if nodeInfo.EnableVless {
|
if nodeInfo.EnableVless {
|
||||||
users = c.buildVlessUsers(userInfo)
|
users = c.buildVlessUsers(userInfo)
|
||||||
} else {
|
} else {
|
||||||
alterID := 0
|
users = c.buildVmessUsers(userInfo)
|
||||||
alterID = (userInfo)[0].V2rayUser.AlterId
|
|
||||||
if alterID >= 0 && alterID < math.MaxUint16 {
|
|
||||||
users = c.buildVmessUsers(userInfo, uint16(alterID))
|
|
||||||
} else {
|
|
||||||
users = c.buildVmessUsers(userInfo, 0)
|
|
||||||
return fmt.Errorf("AlterID should between 0 to 1<<16 - 1, set it to 0 for now")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if nodeInfo.NodeType == "Trojan" {
|
} else if nodeInfo.NodeType == "Trojan" {
|
||||||
users = c.buildTrojanUsers(userInfo)
|
users = c.buildTrojanUsers(userInfo)
|
||||||
@ -225,7 +217,7 @@ func compareUserList(old, new []panel.UserInfo) (deleted, added []panel.UserInfo
|
|||||||
return deleted, added
|
return deleted, added
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) userInfoMonitor() (err error) {
|
func (c *Node) reportUserTraffic() (err error) {
|
||||||
// Get User traffic
|
// Get User traffic
|
||||||
userTraffic := make([]panel.UserTraffic, 0)
|
userTraffic := make([]panel.UserTraffic, 0)
|
||||||
for i := range c.userList {
|
for i := range c.userList {
|
||||||
@ -243,7 +235,7 @@ func (c *Node) userInfoMonitor() (err error) {
|
|||||||
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.Printf("Report user traffic faild: %s", err)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[%s: %d] Report %d online users", c.nodeInfo.NodeType, c.nodeInfo.NodeId, len(userTraffic))
|
log.Printf("[%s: %d] Report %d online users", c.nodeInfo.NodeType, c.nodeInfo.NodeId, len(userTraffic))
|
||||||
}
|
}
|
||||||
@ -256,7 +248,7 @@ func (c *Node) userInfoMonitor() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) onlineIpReport() (err error) {
|
func (c *Node) reportOnlineIp() (err error) {
|
||||||
onlineIp, err := c.server.ListOnlineIp(c.Tag)
|
onlineIp, err := c.server.ListOnlineIp(c.Tag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
@ -292,7 +284,7 @@ func (c *Node) onlineIpReport() (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) DynamicSpeedLimit() error {
|
func (c *Node) dynamicSpeedLimit() error {
|
||||||
if c.config.EnableDynamicSpeedLimit {
|
if c.config.EnableDynamicSpeedLimit {
|
||||||
for i := range c.userList {
|
for i := range c.userList {
|
||||||
up, down := c.server.GetUserTraffic(c.buildUserTag(&(c.userList)[i]), false)
|
up, down := c.server.GetUserTraffic(c.buildUserTag(&(c.userList)[i]), false)
|
||||||
|
@ -13,10 +13,10 @@ import (
|
|||||||
"github.com/xtls/xray-core/proxy/vless"
|
"github.com/xtls/xray-core/proxy/vless"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Node) buildVmessUsers(userInfo []panel.UserInfo, serverAlterID uint16) (users []*protocol.User) {
|
func (c *Node) buildVmessUsers(userInfo []panel.UserInfo) (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, 0)
|
||||||
}
|
}
|
||||||
return users
|
return users
|
||||||
}
|
}
|
||||||
@ -27,12 +27,11 @@ func (c *Node) buildVmessUser(userInfo *panel.UserInfo, serverAlterID uint16) (u
|
|||||||
AlterIds: serverAlterID,
|
AlterIds: serverAlterID,
|
||||||
Security: "auto",
|
Security: "auto",
|
||||||
}
|
}
|
||||||
user = &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: c.buildUserTag(userInfo), // Uid: InboundTag|email|uid
|
Email: c.buildUserTag(userInfo), // Uid: InboundTag|email|uid
|
||||||
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
Account: serial.ToTypedMessage(vmessAccount.Build()),
|
||||||
}
|
}
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) buildVlessUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
func (c *Node) buildVlessUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
||||||
@ -48,12 +47,11 @@ func (c *Node) buildVlessUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
|||||||
Id: userInfo.V2rayUser.Uuid,
|
Id: userInfo.V2rayUser.Uuid,
|
||||||
Flow: "xtls-rprx-direct",
|
Flow: "xtls-rprx-direct",
|
||||||
}
|
}
|
||||||
user = &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: c.buildUserTag(userInfo),
|
Email: c.buildUserTag(userInfo),
|
||||||
Account: serial.ToTypedMessage(vlessAccount),
|
Account: serial.ToTypedMessage(vlessAccount),
|
||||||
}
|
}
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) buildTrojanUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
func (c *Node) buildTrojanUsers(userInfo []panel.UserInfo) (users []*protocol.User) {
|
||||||
@ -69,12 +67,11 @@ func (c *Node) buildTrojanUser(userInfo *panel.UserInfo) (user *protocol.User) {
|
|||||||
Password: userInfo.TrojanUser.Password,
|
Password: userInfo.TrojanUser.Password,
|
||||||
Flow: "xtls-rprx-direct",
|
Flow: "xtls-rprx-direct",
|
||||||
}
|
}
|
||||||
user = &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: c.buildUserTag(userInfo),
|
Email: c.buildUserTag(userInfo),
|
||||||
Account: serial.ToTypedMessage(trojanAccount),
|
Account: serial.ToTypedMessage(trojanAccount),
|
||||||
}
|
}
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCipherFromString(c string) shadowsocks.CipherType {
|
func getCipherFromString(c string) shadowsocks.CipherType {
|
||||||
@ -105,12 +102,11 @@ func (c *Node) buildSSUser(userInfo *panel.UserInfo, cypher shadowsocks.CipherTy
|
|||||||
Password: userInfo.Secret,
|
Password: userInfo.Secret,
|
||||||
CipherType: cypher,
|
CipherType: cypher,
|
||||||
}
|
}
|
||||||
user = &protocol.User{
|
return &protocol.User{
|
||||||
Level: 0,
|
Level: 0,
|
||||||
Email: c.buildUserTag(userInfo),
|
Email: c.buildUserTag(userInfo),
|
||||||
Account: serial.ToTypedMessage(ssAccount),
|
Account: serial.ToTypedMessage(ssAccount),
|
||||||
}
|
}
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Node) buildUserTag(user *panel.UserInfo) string {
|
func (c *Node) buildUserTag(user *panel.UserInfo) string {
|
Loading…
Reference in New Issue
Block a user