mirror of
https://github.com/wyx2685/V2bX.git
synced 2026-02-04 12:40:11 +00:00
move some code
This commit is contained in:
62
core/node.go
Normal file
62
core/node.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/Yuzuki616/V2bX/api/panel"
|
||||
"github.com/Yuzuki616/V2bX/common/builder"
|
||||
"github.com/Yuzuki616/V2bX/conf"
|
||||
"github.com/xtls/xray-core/core"
|
||||
"github.com/xtls/xray-core/features/inbound"
|
||||
)
|
||||
|
||||
func (c *Core) AddNode(tag string, info *panel.NodeInfo, config *conf.ControllerConfig) error {
|
||||
inboundConfig, err := builder.BuildInbound(config, info, tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build inbound error: %s", err)
|
||||
}
|
||||
err = c.addInbound(inboundConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("add inbound error: %s", err)
|
||||
}
|
||||
outBoundConfig, err := builder.BuildOutbound(config, info, tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("build outbound error: %s", err)
|
||||
}
|
||||
err = c.AddOutbound(outBoundConfig)
|
||||
if err != nil {
|
||||
return fmt.Errorf("add outbound error: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) addInbound(config *core.InboundHandlerConfig) error {
|
||||
rawHandler, err := core.CreateObject(c.Server, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
handler, ok := rawHandler.(inbound.Handler)
|
||||
if !ok {
|
||||
return fmt.Errorf("not an InboundHandler: %s", err)
|
||||
}
|
||||
if err := c.ihm.AddHandler(context.Background(), handler); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) DelNode(tag string) error {
|
||||
err := c.removeInbound(tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove in error: %s", err)
|
||||
}
|
||||
err = c.RemoveOutbound(tag)
|
||||
if err != nil {
|
||||
return fmt.Errorf("remove out error: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Core) removeInbound(tag string) error {
|
||||
return c.ihm.RemoveHandler(context.Background(), tag)
|
||||
}
|
||||
Reference in New Issue
Block a user