2023-06-08 10:46:33 -04:00
|
|
|
package hy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2023-07-27 21:13:11 -04:00
|
|
|
|
2023-06-08 10:46:33 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
|
|
|
"github.com/Yuzuki616/V2bX/conf"
|
2023-06-15 22:04:39 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/limiter"
|
2023-06-08 10:46:33 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Hy) AddNode(tag string, info *panel.NodeInfo, c *conf.ControllerConfig) error {
|
|
|
|
if info.Type != "hysteria" {
|
|
|
|
return errors.New("the core not support " + info.Type)
|
|
|
|
}
|
2023-06-09 00:36:49 -04:00
|
|
|
switch c.CertConfig.CertMode {
|
|
|
|
case "reality", "none", "":
|
|
|
|
return errors.New("hysteria need normal tls cert")
|
|
|
|
}
|
2023-06-15 22:04:39 -04:00
|
|
|
l, err := limiter.GetLimiter(tag)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("get limiter error: %s", err)
|
|
|
|
}
|
|
|
|
s := NewServer(tag, l)
|
|
|
|
err = s.runServer(info, c)
|
2023-06-08 10:46:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("run hy server error: %s", err)
|
|
|
|
}
|
|
|
|
h.servers.Store(tag, s)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hy) DelNode(tag string) error {
|
|
|
|
if s, e := h.servers.Load(tag); e {
|
2023-06-18 20:34:59 -04:00
|
|
|
err := s.(*Server).Close()
|
2023-06-08 10:46:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
h.servers.Delete(tag)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return errors.New("the node is not have")
|
|
|
|
}
|