2022-07-28 11:00:05 -04:00
|
|
|
package node
|
2022-06-01 13:35:41 -04:00
|
|
|
|
|
|
|
import (
|
2022-08-16 01:04:33 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
2022-07-28 11:00:05 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/conf"
|
2022-08-12 06:02:06 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/core"
|
2022-10-09 23:31:15 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/node/controller"
|
2022-06-01 13:35:41 -04:00
|
|
|
)
|
|
|
|
|
2022-07-28 11:00:05 -04:00
|
|
|
type Node struct {
|
2022-10-09 23:31:15 -04:00
|
|
|
controllers []*controller.Node
|
2022-06-01 13:35:41 -04:00
|
|
|
}
|
|
|
|
|
2022-10-09 23:31:15 -04:00
|
|
|
func New() *Node {
|
|
|
|
return &Node{}
|
2022-06-01 13:35:41 -04:00
|
|
|
}
|
|
|
|
|
2022-10-09 23:31:15 -04:00
|
|
|
func (n *Node) Start(nodes []*conf.NodeConfig, core *core.Core) error {
|
|
|
|
n.controllers = make([]*controller.Node, len(nodes))
|
|
|
|
for i, c := range nodes {
|
2022-12-18 10:31:06 -05:00
|
|
|
p, err := panel.New(c.ApiConfig)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-09 23:31:15 -04:00
|
|
|
// Register controller service
|
2022-12-18 10:31:06 -05:00
|
|
|
n.controllers[i] = controller.New(core, p, c.ControllerConfig)
|
|
|
|
err = n.controllers[i].Start()
|
2022-10-09 23:31:15 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2022-09-07 11:02:02 -04:00
|
|
|
}
|
|
|
|
}
|
2022-06-01 13:35:41 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-10-09 23:31:15 -04:00
|
|
|
func (n *Node) Close() {
|
|
|
|
for _, c := range n.controllers {
|
|
|
|
err := c.Close()
|
2022-10-09 20:59:00 -04:00
|
|
|
if err != nil {
|
2022-10-09 23:31:15 -04:00
|
|
|
panic(err)
|
2022-10-09 20:59:00 -04:00
|
|
|
}
|
|
|
|
}
|
2022-10-09 23:31:15 -04:00
|
|
|
n.controllers = nil
|
2022-06-01 13:35:41 -04:00
|
|
|
}
|