mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 04:30:08 +00:00
update singbox
This commit is contained in:
@@ -3,6 +3,7 @@ package xray
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/InazumaV/V2bX/api/panel"
|
||||
"github.com/InazumaV/V2bX/conf"
|
||||
"github.com/xtls/xray-core/core"
|
||||
@@ -15,7 +16,7 @@ type DNSConfig struct {
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||
func (c *Xray) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) error {
|
||||
err := updateDNSConfig(info)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build dns error: %s", err)
|
||||
@@ -39,7 +40,7 @@ func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.Options) e
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) addInbound(config *core.InboundHandlerConfig) error {
|
||||
func (c *Xray) addInbound(config *core.InboundHandlerConfig) error {
|
||||
rawHandler, err := core.CreateObject(c.Server, config)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -54,7 +55,7 @@ func (c *Core) addInbound(config *core.InboundHandlerConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) addOutbound(config *core.OutboundHandlerConfig) error {
|
||||
func (c *Xray) addOutbound(config *core.OutboundHandlerConfig) error {
|
||||
rawHandler, err := core.CreateObject(c.Server, config)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -69,7 +70,7 @@ func (c *Core) addOutbound(config *core.OutboundHandlerConfig) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) DelNode(tag string) error {
|
||||
func (c *Xray) DelNode(tag string) error {
|
||||
err := c.removeInbound(tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove in error: %s", err)
|
||||
@@ -81,11 +82,11 @@ func (c *Core) DelNode(tag string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) removeInbound(tag string) error {
|
||||
func (c *Xray) removeInbound(tag string) error {
|
||||
return c.ihm.RemoveHandler(context.Background(), tag)
|
||||
}
|
||||
|
||||
func (c *Core) removeOutbound(tag string) error {
|
||||
func (c *Xray) removeOutbound(tag string) error {
|
||||
err := c.ohm.RemoveHandler(context.Background(), tag)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/xtls/xray-core/proxy"
|
||||
)
|
||||
|
||||
func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
|
||||
func (c *Xray) GetUserManager(tag string) (proxy.UserManager, error) {
|
||||
handler, err := c.ihm.GetHandler(context.Background(), tag)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no such inbound tag: %s", err)
|
||||
@@ -27,7 +27,7 @@ func (c *Core) GetUserManager(tag string) (proxy.UserManager, error) {
|
||||
return userManager, nil
|
||||
}
|
||||
|
||||
func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
|
||||
func (c *Xray) DelUsers(users []panel.UserInfo, tag string) error {
|
||||
userManager, err := c.GetUserManager(tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get user manager error: %s", err)
|
||||
@@ -47,7 +47,7 @@ func (c *Core) DelUsers(users []panel.UserInfo, tag string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
||||
func (c *Xray) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
||||
upName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>uplink"
|
||||
downName := "user>>>" + format.UserTag(tag, uuid) + ">>>traffic>>>downlink"
|
||||
upCounter := c.shm.GetCounter(upName)
|
||||
@@ -70,7 +70,7 @@ func (c *Core) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int6
|
||||
return up, down
|
||||
}
|
||||
|
||||
func (c *Core) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
||||
func (c *Xray) AddUsers(p *vCore.AddUsersParams) (added int, err error) {
|
||||
users := make([]*protocol.User, 0, len(p.Users))
|
||||
switch p.NodeInfo.Type {
|
||||
case "vmess":
|
||||
|
||||
@@ -22,12 +22,14 @@ import (
|
||||
coreConf "github.com/xtls/xray-core/infra/conf"
|
||||
)
|
||||
|
||||
var _ vCore.Core = (*Xray)(nil)
|
||||
|
||||
func init() {
|
||||
vCore.RegisterCore("xray", New)
|
||||
}
|
||||
|
||||
// Core Structure
|
||||
type Core struct {
|
||||
// Xray Structure
|
||||
type Xray struct {
|
||||
access sync.Mutex
|
||||
Server *core.Instance
|
||||
ihm inbound.Manager
|
||||
@@ -37,7 +39,7 @@ type Core struct {
|
||||
}
|
||||
|
||||
func New(c *conf.CoreConfig) (vCore.Core, error) {
|
||||
return &Core{Server: getCore(c.XrayConfig)}, nil
|
||||
return &Xray{Server: getCore(c.XrayConfig)}, nil
|
||||
}
|
||||
|
||||
func parseConnectionConfig(c *conf.XrayConnectionConfig) (policy *coreConf.Policy) {
|
||||
@@ -137,7 +139,7 @@ func getCore(c *conf.XrayConfig) *core.Instance {
|
||||
corePolicyConfig := &coreConf.PolicyConfig{}
|
||||
corePolicyConfig.Levels = map[uint32]*coreConf.Policy{0: levelPolicyConfig}
|
||||
policyConfig, _ := corePolicyConfig.Build()
|
||||
// Build Core conf
|
||||
// Build Xray conf
|
||||
config := &core.Config{
|
||||
App: []*serial.TypedMessage{
|
||||
serial.ToTypedMessage(coreLogConfig.Build()),
|
||||
@@ -160,8 +162,8 @@ func getCore(c *conf.XrayConfig) *core.Instance {
|
||||
return server
|
||||
}
|
||||
|
||||
// Start the Core
|
||||
func (c *Core) Start() error {
|
||||
// Start the Xray
|
||||
func (c *Xray) Start() error {
|
||||
c.access.Lock()
|
||||
defer c.access.Unlock()
|
||||
if err := c.Server.Start(); err != nil {
|
||||
@@ -175,7 +177,7 @@ func (c *Core) Start() error {
|
||||
}
|
||||
|
||||
// Close the core
|
||||
func (c *Core) Close() error {
|
||||
func (c *Xray) Close() error {
|
||||
c.access.Lock()
|
||||
defer c.access.Unlock()
|
||||
c.ihm = nil
|
||||
@@ -189,7 +191,7 @@ func (c *Core) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) Protocols() []string {
|
||||
func (c *Xray) Protocols() []string {
|
||||
return []string{
|
||||
"vmess",
|
||||
"vless",
|
||||
@@ -198,6 +200,6 @@ func (c *Core) Protocols() []string {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Core) Type() string {
|
||||
func (c *Xray) Type() string {
|
||||
return "xray"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user